libusb / hidapi

A Simple cross-platform library for communicating with HID devices
https://libusb.info/hidapi/
Other
1.68k stars 398 forks source link

Windows: return bytes_written in hid_write if WriteFile returns 1 (succeeds synchronously) #697

Closed Megamouse closed 1 month ago

Megamouse commented 1 month ago

Return bytes_written in hid_write if WriteFile returns 1, which means it succeeded synchronously.

According to documentation, the system reserves the right to run WriteFile synchronously, even if FILE_FLAG_OVERLAPPED is set.

"Be careful when you code for asynchronous I/O because the system reserves the right to make an operation synchronous if it needs to. So it is best if you write the program to correctly handle an I/O operation that may be completed either synchronously or asynchronously. The sample code demonstrates this consideration."

Fixes #695

Megamouse commented 1 month ago

I've been looking at hid_read_timeout as well. It luckily seems to handle synchronous reads correctly already, since it already passes bytes_read to ReadFile and uses it later to write to the read_buf.

Youw commented 1 month ago

@mcuee can you have a quick check of this with known devices you have? I'm pretty sure this is fine, but just to be sure

mcuee commented 1 month ago

@mcuee can you have a quick check of this with known devices you have? I'm pretty sure this is fine, but just to be sure

I will carry out the tests over the weekend.

mcuee commented 1 month ago

Building is fine with VS2022 and MinGW64 (cmake and auto-tools).

CMake MSYS2 mingw64 build log ``` MINGW64 /c/work/hid/hidapi_pr697 $ cat build_verbose.sh cmake -B build_mingw -D CMAKE_VERBOSE_MAKEFILE=ON -D CMAKE_BUILD_TYPE=RelWithDebInfo -D HIDAPI_BUILD_HIDTEST=ON -D HIDAPI_WITH_TESTS=ON -D HIDAPI_BUILD_PP_DATA_DUMP=ON -D CMAKE_C_FLAGS="-Wall -Wextra -pedantic -Werror" cmake --build build_mingw $ sh build_verbose.sh -- Building for: Ninja -- The C compiler identification is GNU 13.2.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: C:/msys64/mingw64/bin/cc.exe - skipped -- Detecting C compile features -- Detecting C compile features - done -- hidapi: v0.15.0 -- Building hidtest -- Configuring done (1.0s) -- Generating done (0.0s) -- Build files have been written to: C:/work/hid/hidapi_pr697/build_mingw Change Dir: 'C:/work/hid/hidapi_pr697/build_mingw' Run Build Command(s): C:/msys64/mingw64/bin/ninja.exe -v [1/10] C:\msys64\mingw64\bin\windres.exe -O coff -Dhidapi_winapi_EXPORTS -I C:/work/hid/hidapi_pr697/hidapi -I C:/work/hid/hidapi_pr697/windows C:/work/hid/hidapi_pr697/windows/hidapi.rc src/windows/CMakeFiles/hidapi_winapi.dir/hidapi.rc.obj [2/10] C:\msys64\mingw64\bin\cc.exe -IC:/work/hid/hidapi_pr697/hidapi -IC:/work/hid/hidapi_pr697/windows -Wall -Wextra -pedantic -Werror -O2 -g -DNDEBUG -MD -MT hidtest/CMakeFiles/hidtest.dir/test.c.obj -MF hidtest\CMakeFiles\hidtest.dir\test.c.obj.d -o hidtest/CMakeFiles/hidtest.dir/test.c.obj -c C:/work/hid/hidapi_pr697/hidtest/test.c [3/10] C:\msys64\mingw64\bin\cc.exe -IC:/work/hid/hidapi_pr697/hidapi -IC:/work/hid/hidapi_pr697/windows -Wall -Wextra -pedantic -Werror -O2 -g -DNDEBUG -std=gnu11 -MD -MT src/windows/test/CMakeFiles/hid_report_reconstructor_test.dir/hid_report_reconstructor_test.c.obj -MF src\windows\test\CMakeFiles\hid_report_reconstructor_test.dir\hid_report_reconstructor_test.c.obj.d -o src/windows/test/CMakeFiles/hid_report_reconstructor_test.dir/hid_report_reconstructor_test.c.obj -c C:/work/hid/hidapi_pr697/windows/test/hid_report_reconstructor_test.c [4/10] C:\msys64\mingw64\bin\cc.exe -Dhidapi_winapi_EXPORTS -IC:/work/hid/hidapi_pr697/hidapi -IC:/work/hid/hidapi_pr697/windows -Wall -Wextra -pedantic -Werror -O2 -g -DNDEBUG -MD -MT src/windows/CMakeFiles/hidapi_winapi.dir/hid.c.obj -MF src\windows\CMakeFiles\hidapi_winapi.dir\hid.c.obj.d -o src/windows/CMakeFiles/hidapi_winapi.dir/hid.c.obj -c C:/work/hid/hidapi_pr697/windows/hid.c [5/10] C:\msys64\mingw64\bin\cc.exe -Dhidapi_winapi_EXPORTS -IC:/work/hid/hidapi_pr697/hidapi -IC:/work/hid/hidapi_pr697/windows -Wall -Wextra -pedantic -Werror -O2 -g -DNDEBUG -MD -MT src/windows/CMakeFiles/hidapi_winapi.dir/hidapi_descriptor_reconstruct.c.obj -MF src\windows\CMakeFiles\hidapi_winapi.dir\hidapi_descriptor_reconstruct.c.obj.d -o src/windows/CMakeFiles/hidapi_winapi.dir/hidapi_descriptor_reconstruct.c.obj -c C:/work/hid/hidapi_pr697/windows/hidapi_descriptor_reconstruct.c [6/10] C:\WINDOWS\system32\cmd.exe /C "cd . && C:\msys64\mingw64\bin\cc.exe -Wall -Wextra -pedantic -Werror -O2 -g -DNDEBUG -shared -o src\windows\libhidapi.dll -Wl,--out-implib,src\windows\libhidapi.dll.a -Wl,--major-image-version,0,--minor-image-version,15 src/windows/CMakeFiles/hidapi_winapi.dir/hid.c.obj src/windows/CMakeFiles/hidapi_winapi.dir/hidapi_descriptor_reconstruct.c.obj src/windows/CMakeFiles/hidapi_winapi.dir/hidapi.rc.obj -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ." [7/10] C:\WINDOWS\system32\cmd.exe /C "cd . && C:\msys64\mingw64\bin\cc.exe -Wall -Wextra -pedantic -Werror -O2 -g -DNDEBUG src/windows/test/CMakeFiles/hid_report_reconstructor_test.dir/hid_report_reconstructor_test.c.obj -o src\windows\test\hid_report_reconstructor_test.exe -Wl,--out-implib,src\windows\test\libhid_report_reconstructor_test.dll.a -Wl,--major-image-version,0,--minor-image-version,0 src/windows/libhidapi.dll.a -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ." [8/10] C:\WINDOWS\system32\cmd.exe /C "cd . && C:\msys64\mingw64\bin\cc.exe -Wall -Wextra -pedantic -Werror -O2 -g -DNDEBUG hidtest/CMakeFiles/hidtest.dir/test.c.obj -o hidtest\hidtest.exe -Wl,--out-implib,hidtest\libhidtest.dll.a -Wl,--major-image-version,0,--minor-image-version,0 src/windows/libhidapi.dll.a -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ." [9/10] C:\msys64\mingw64\bin\cc.exe -IC:/work/hid/hidapi_pr697/hidapi -IC:/work/hid/hidapi_pr697/windows -Wall -Wextra -pedantic -Werror -O2 -g -DNDEBUG -std=gnu11 -MD -MT src/windows/pp_data_dump/CMakeFiles/pp_data_dump.dir/pp_data_dump.c.obj -MF src\windows\pp_data_dump\CMakeFiles\pp_data_dump.dir\pp_data_dump.c.obj.d -o src/windows/pp_data_dump/CMakeFiles/pp_data_dump.dir/pp_data_dump.c.obj -c C:/work/hid/hidapi_pr697/windows/pp_data_dump/pp_data_dump.c [10/10] C:\WINDOWS\system32\cmd.exe /C "cd . && C:\msys64\mingw64\bin\cc.exe -Wall -Wextra -pedantic -Werror -O2 -g -DNDEBUG src/windows/pp_data_dump/CMakeFiles/pp_data_dump.dir/pp_data_dump.c.obj -o src\windows\pp_data_dump\pp_data_dump.exe -Wl,--out-implib,src\windows\pp_data_dump\libpp_data_dump.dll.a -Wl,--major-image-version,0,--minor-image-version,0 src/windows/libhidapi.dll.a -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ." ```
mcuee commented 1 month ago

Simple hidtest output (with Microchip Simple HID Demo).

Output from hidtest.exe ``` $ ./hidtest.exe hidapi test/example tool. Compiled with hidapi version 0.15.0, runtime version 0.15.0. Compile-time version matches runtime version of hidapi. Device Found type: 046d b021 path: \\?\HID#{00001812-0000-1000-8000-00805f9b34fb}_Dev_VID&02046d_PID&b021_REV&0007_fd9c982ff43f&Col01#9&3abb00b2&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030} serial_number: fd9c982ff43f Manufacturer: Logitech Product: Logitech_Pebble Release: 7 Interface: -1 Usage (page): 0x2 (0x1) Bus type: 2 (Bluetooth) Report Descriptor: (75 bytes) 0x05, 0x01, 0x09, 0x02, 0xa1, 0x01, 0x09, 0x01, 0xa1, 0x00, 0x85, 0x02, 0x05, 0x09, 0x19, 0x01, 0x29, 0x10, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x10, 0x81, 0x02, 0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x16, 0x01, 0xf8, 0x26, 0xff, 0x07, 0x75, 0x0c, 0x95, 0x02, 0x81, 0x06, 0x09, 0x38, 0x15, 0x81, 0x25, 0x7f, 0x75, 0x08, 0x95, 0x01, 0x81, 0x06, 0x05, 0x0c, 0x0a, 0x38, 0x02, 0x15, 0x81, 0x25, 0x7f, 0x75, 0x08, 0x95, 0x01, 0x81, 0x06, 0xc0, 0xc0, Device Found type: 046d b021 path: \\?\HID#{00001812-0000-1000-8000-00805f9b34fb}_Dev_VID&02046d_PID&b021_REV&0007_fd9c982ff43f&Col02#9&3abb00b2&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030} serial_number: fd9c982ff43f Manufacturer: Logitech Product: Logitech_Pebble Release: 7 Interface: -1 Usage (page): 0x202 (0xff43) Bus type: 2 (Bluetooth) Report Descriptor: (37 bytes) 0x06, 0x43, 0xff, 0x0a, 0x02, 0x02, 0xa1, 0x01, 0x85, 0x11, 0x09, 0x02, 0x15, 0x00, 0x26, 0xff, 0x00, 0x75, 0x08, 0x95, 0x13, 0x81, 0x00, 0x09, 0x02, 0x15, 0x00, 0x26, 0xff, 0x00, 0x75, 0x08, 0x95, 0x13, 0x91, 0x00, 0xc0, Device Found type: 8087 0a1e path: \\?\HID#INTC816#3&d2322f2&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030} serial_number: Manufacturer: Product: Release: 200 Interface: -1 Usage (page): 0xd (0x1) Bus type: 0 (Unknown) Report Descriptor: (50 bytes) 0x05, 0x01, 0x09, 0x0d, 0xa1, 0x01, 0x09, 0x0d, 0xa1, 0x02, 0x85, 0x1c, 0x09, 0x81, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x01, 0x81, 0x02, 0x75, 0x07, 0x95, 0x01, 0x81, 0x03, 0x09, 0xcb, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x01, 0xb1, 0x02, 0x75, 0x07, 0x95, 0x01, 0xb1, 0x03, 0xc0, 0xc0, Device Found type: 06cb cd40 path: \\?\HID#SYNA7DAB&Col01#5&2f64dfea&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030} serial_number: 9999 Manufacturer: Microsoft Product: HIDI2C Device Release: 501 Interface: -1 Usage (page): 0x2 (0x1) Bus type: 3 (I2C) Report Descriptor: (52 bytes) 0x05, 0x01, 0x09, 0x02, 0xa1, 0x01, 0x09, 0x01, 0xa1, 0x00, 0x85, 0x02, 0x05, 0x09, 0x19, 0x01, 0x29, 0x02, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x02, 0x81, 0x02, 0x75, 0x06, 0x95, 0x01, 0x81, 0x03, 0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x15, 0x81, 0x25, 0x7f, 0x75, 0x08, 0x95, 0x02, 0x81, 0x06, 0xc0, 0xc0, Device Found type: 06cb cd40 path: \\?\HID#SYNA7DAB&Col02#5&2f64dfea&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030} serial_number: 9999 Manufacturer: Microsoft Product: HIDI2C Device Release: 501 Interface: -1 Usage (page): 0x5 (0xd) Bus type: 3 (I2C) Report Descriptor: (610 bytes) 0x05, 0x0d, 0x09, 0x05, 0xa1, 0x01, 0x09, 0x22, 0xa1, 0x02, 0x85, 0x03, 0x09, 0x47, 0x09, 0x42, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x02, 0x81, 0x02, 0x09, 0x51, 0x15, 0x00, 0x25, 0x05, 0x75, 0x03, 0x95, 0x01, 0x81, 0x02, 0x75, 0x03, 0x95, 0x01, 0x81, 0x03, 0x05, 0x01, 0x09, 0x30, 0x15, 0x00, 0x26, 0xc8, 0x04, 0x35, 0x00, 0x46, 0xfc, 0x03, 0x55, 0x0e, 0x65, 0x11, 0x75, 0x10, 0x95, 0x01, 0x81, 0x02, 0x09, 0x31, 0x15, 0x00, 0x26, 0xe8, 0x02, 0x35, 0x00, 0x46, 0x6c, 0x02, 0x75, 0x10, 0x95, 0x01, 0x81, 0x02, 0xc0, 0x05, 0x0d, 0x09, 0x22, 0xa1, 0x02, 0x09, 0x47, 0x09, 0x42, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x02, 0x45, 0x00, 0x55, 0x00, 0x65, 0x00, 0x81, 0x02, 0x09, 0x51, 0x15, 0x00, 0x25, 0x05, 0x35, 0x00, 0x46, 0x6c, 0x02, 0x55, 0x0e, 0x65, 0x11, 0x75, 0x03, 0x95, 0x01, 0x81, 0x02, 0x75, 0x03, 0x95, 0x01, 0x81, 0x03, 0x05, 0x01, 0x09, 0x30, 0x15, 0x00, 0x26, 0xc8, 0x04, 0x35, 0x00, 0x46, 0xfc, 0x03, 0x75, 0x10, 0x95, 0x01, 0x81, 0x02, 0x09, 0x31, 0x15, 0x00, 0x26, 0xe8, 0x02, 0x35, 0x00, 0x46, 0x6c, 0x02, 0x75, 0x10, 0x95, 0x01, 0x81, 0x02, 0xc0, 0x05, 0x0d, 0x09, 0x22, 0xa1, 0x02, 0x09, 0x47, 0x09, 0x42, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x02, 0x45, 0x00, 0x55, 0x00, 0x65, 0x00, 0x81, 0x02, 0x09, 0x51, 0x15, 0x00, 0x25, 0x05, 0x35, 0x00, 0x46, 0x6c, 0x02, 0x55, 0x0e, 0x65, 0x11, 0x75, 0x03, 0x95, 0x01, 0x81, 0x02, 0x75, 0x03, 0x95, 0x01, 0x81, 0x03, 0x05, 0x01, 0x09, 0x30, 0x15, 0x00, 0x26, 0xc8, 0x04, 0x35, 0x00, 0x46, 0xfc, 0x03, 0x75, 0x10, 0x95, 0x01, 0x81, 0x02, 0x09, 0x31, 0x15, 0x00, 0x26, 0xe8, 0x02, 0x35, 0x00, 0x46, 0x6c, 0x02, 0x75, 0x10, 0x95, 0x01, 0x81, 0x02, 0xc0, 0x05, 0x0d, 0x09, 0x22, 0xa1, 0x02, 0x09, 0x47, 0x09, 0x42, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x02, 0x45, 0x00, 0x55, 0x00, 0x65, 0x00, 0x81, 0x02, 0x09, 0x51, 0x15, 0x00, 0x25, 0x05, 0x35, 0x00, 0x46, 0x6c, 0x02, 0x55, 0x0e, 0x65, 0x11, 0x75, 0x03, 0x95, 0x01, 0x81, 0x02, 0x75, 0x03, 0x95, 0x01, 0x81, 0x03, 0x05, 0x01, 0x09, 0x30, 0x15, 0x00, 0x26, 0xc8, 0x04, 0x35, 0x00, 0x46, 0xfc, 0x03, 0x75, 0x10, 0x95, 0x01, 0x81, 0x02, 0x09, 0x31, 0x15, 0x00, 0x26, 0xe8, 0x02, 0x35, 0x00, 0x46, 0x6c, 0x02, 0x75, 0x10, 0x95, 0x01, 0x81, 0x02, 0xc0, 0x05, 0x0d, 0x09, 0x22, 0xa1, 0x02, 0x09, 0x47, 0x09, 0x42, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x02, 0x45, 0x00, 0x55, 0x00, 0x65, 0x00, 0x81, 0x02, 0x09, 0x51, 0x15, 0x00, 0x25, 0x05, 0x35, 0x00, 0x46, 0x6c, 0x02, 0x55, 0x0e, 0x65, 0x11, 0x75, 0x03, 0x95, 0x01, 0x81, 0x02, 0x75, 0x03, 0x95, 0x01, 0x81, 0x03, 0x05, 0x01, 0x09, 0x30, 0x15, 0x00, 0x26, 0xc8, 0x04, 0x35, 0x00, 0x46, 0xfc, 0x03, 0x75, 0x10, 0x95, 0x01, 0x81, 0x02, 0x09, 0x31, 0x15, 0x00, 0x26, 0xe8, 0x02, 0x35, 0x00, 0x46, 0x6c, 0x02, 0x75, 0x10, 0x95, 0x01, 0x81, 0x02, 0xc0, 0x05, 0x0d, 0x09, 0x56, 0x15, 0x00, 0x27, 0xff, 0xff, 0x00, 0x00, 0x35, 0x00, 0x47, 0xff, 0xff, 0x00, 0x00, 0x55, 0x0c, 0x66, 0x01, 0x10, 0x75, 0x10, 0x95, 0x01, 0x81, 0x02, 0x09, 0x54, 0x15, 0x00, 0x25, 0x7f, 0x75, 0x08, 0x95, 0x01, 0x81, 0x02, 0x05, 0x09, 0x09, 0x01, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x01, 0x45, 0x00, 0x55, 0x00, 0x65, 0x00, 0x81, 0x02, 0x75, 0x07, 0x95, 0x01, 0x81, 0x03, 0x85, 0x08, 0x05, 0x0d, 0x09, 0x55, 0x09, 0x59, 0x15, 0x00, 0x25, 0x0f, 0x35, 0x00, 0x47, 0xff, 0xff, 0x00, 0x00, 0x55, 0x0c, 0x66, 0x01, 0x10, 0x75, 0x04, 0x95, 0x02, 0xb1, 0x02, 0x85, 0x0d, 0x09, 0x60, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x01, 0x45, 0x00, 0x55, 0x00, 0x65, 0x00, 0xb1, 0x02, 0x75, 0x07, 0x95, 0x01, 0xb1, 0x03, 0x85, 0x07, 0x06, 0x00, 0xff, 0x09, 0xc5, 0x15, 0x00, 0x26, 0xff, 0x00, 0x35, 0x00, 0x47, 0xff, 0xff, 0x00, 0x00, 0x55, 0x0c, 0x66, 0x01, 0x10, 0x75, 0x08, 0x96, 0x00, 0x01, 0xb1, 0x02, 0xc0, Device Found type: 06cb cd40 path: \\?\HID#SYNA7DAB&Col03#5&2f64dfea&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030} serial_number: 9999 Manufacturer: Microsoft Product: HIDI2C Device Release: 501 Interface: -1 Usage (page): 0xe (0xd) Bus type: 3 (I2C) Report Descriptor: (71 bytes) 0x05, 0x0d, 0x09, 0x0e, 0xa1, 0x01, 0x09, 0x22, 0xa1, 0x02, 0x85, 0x04, 0x09, 0x52, 0x15, 0x00, 0x25, 0x0a, 0x35, 0x00, 0x47, 0xff, 0xff, 0x00, 0x00, 0x55, 0x0c, 0x66, 0x01, 0x10, 0x75, 0x08, 0x95, 0x01, 0xb1, 0x02, 0xc0, 0x09, 0x22, 0xa1, 0x00, 0x85, 0x06, 0x09, 0x57, 0x09, 0x58, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x02, 0x45, 0x00, 0x55, 0x00, 0x65, 0x00, 0xb1, 0x02, 0x75, 0x06, 0x95, 0x01, 0xb1, 0x03, 0xc0, 0xc0, Device Found type: 06cb cd40 path: \\?\HID#SYNA7DAB&Col04#5&2f64dfea&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030} serial_number: 9999 Manufacturer: Microsoft Product: HIDI2C Device Release: 501 Interface: -1 Usage (page): 0x1 (0xff00) Bus type: 3 (I2C) Report Descriptor: (110 bytes) 0x06, 0x00, 0xff, 0x09, 0x01, 0xa1, 0x01, 0x85, 0x0b, 0x09, 0x04, 0x15, 0x00, 0x26, 0xff, 0x00, 0x35, 0x00, 0x47, 0xff, 0xff, 0x00, 0x00, 0x55, 0x0c, 0x66, 0x01, 0x10, 0x75, 0x08, 0x95, 0x3d, 0x81, 0x02, 0x85, 0x0c, 0x09, 0x05, 0x15, 0x00, 0x26, 0xff, 0x00, 0x75, 0x08, 0x95, 0x3d, 0x81, 0x02, 0x85, 0x09, 0x09, 0x02, 0x15, 0x00, 0x26, 0xff, 0x00, 0x75, 0x08, 0x95, 0x14, 0x91, 0x02, 0x85, 0x0a, 0x09, 0x03, 0x15, 0x00, 0x26, 0xff, 0x00, 0x75, 0x08, 0x95, 0x14, 0x91, 0x02, 0x85, 0x0f, 0x09, 0x06, 0x15, 0x00, 0x26, 0xff, 0x00, 0x75, 0x08, 0x95, 0x03, 0xb1, 0x02, 0x85, 0x0e, 0x09, 0x07, 0x15, 0x00, 0x26, 0xff, 0x00, 0x75, 0x08, 0x95, 0x01, 0xb1, 0x02, 0xc0, Device Found type: 045e 0000 path: \\?\HID#ConvertedDevice&Col02#5&32cf90e6&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030} serial_number: Manufacturer: Product: Release: 0 Interface: -1 Usage (page): 0x1 (0xc) Bus type: 0 (Unknown) Report Descriptor: (32 bytes) 0x05, 0x0c, 0x09, 0x01, 0xa1, 0x01, 0x85, 0x02, 0x09, 0xe9, 0x09, 0xea, 0x0a, 0x21, 0x02, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x03, 0x81, 0x02, 0x75, 0x05, 0x95, 0x01, 0x81, 0x03, 0xc0, Device Found type: 045e 0000 path: \\?\HID#ConvertedDevice&Col03#5&32cf90e6&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030} serial_number: Manufacturer: Product: Release: 0 Interface: -1 Usage (page): 0x80 (0x1) Bus type: 0 (Unknown) Report Descriptor: (27 bytes) 0x05, 0x01, 0x09, 0x80, 0xa1, 0x01, 0x85, 0x03, 0x09, 0x81, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x01, 0x81, 0x02, 0x75, 0x07, 0x95, 0x01, 0x81, 0x03, 0xc0, Device Found type: deed feed path: \\?\HID#10251229#3&9d5d338&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030} serial_number: Manufacturer: Acer Inc Product: Acer Airplane Mode Controller Release: 101 Interface: -1 Usage (page): 0xc (0x1) Bus type: 0 (Unknown) Report Descriptor: (27 bytes) 0x05, 0x01, 0x09, 0x0c, 0xa1, 0x01, 0x85, 0x01, 0x09, 0xc6, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x01, 0x81, 0x06, 0x75, 0x07, 0x95, 0x01, 0x81, 0x03, 0xc0, Device Found type: 045e 0000 path: \\?\HID#ConvertedDevice&Col01#5&32cf90e6&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\KBD serial_number: Manufacturer: Product: Release: 0 Interface: -1 Usage (page): 0x6 (0x1) Bus type: 0 (Unknown) Report Descriptor: (37 bytes) 0x05, 0x01, 0x09, 0x06, 0xa1, 0x01, 0x85, 0x01, 0x05, 0x07, 0x09, 0x69, 0x09, 0x6a, 0x09, 0x6b, 0x09, 0x6c, 0x09, 0xe3, 0x09, 0x4c, 0x09, 0xe2, 0x09, 0xe0, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x08, 0x81, 0x02, 0xc0, Device Found type: 1ea7 0064 path: \\?\HID#VID_1EA7&PID_0064&Col01#6&32073eda&1&0000#{4d1e55b2-f16f-11cf-88cb-001111000030} serial_number: Manufacturer: (Standard system devices) Product: 2.4G Mouse Release: 200 Interface: 0 Usage (page): 0x1 (0xffb5) Bus type: 1 (USB) Report Descriptor: (36 bytes) 0x06, 0xb5, 0xff, 0x09, 0x01, 0xa1, 0x01, 0x85, 0xb5, 0x09, 0x02, 0x15, 0x00, 0x26, 0xff, 0x00, 0x75, 0x08, 0x95, 0x07, 0x81, 0x02, 0x09, 0x02, 0x15, 0x00, 0x26, 0xff, 0x00, 0x75, 0x08, 0x95, 0x07, 0x91, 0x02, 0xc0, Device Found type: 1ea7 0064 path: \\?\HID#VID_1EA7&PID_0064&Col02#6&32073eda&1&0001#{4d1e55b2-f16f-11cf-88cb-001111000030} serial_number: Manufacturer: (Standard system devices) Product: 2.4G Mouse Release: 200 Interface: 0 Usage (page): 0x2 (0x1) Bus type: 1 (USB) Report Descriptor: (75 bytes) 0x05, 0x01, 0x09, 0x02, 0xa1, 0x01, 0x09, 0x01, 0xa1, 0x00, 0x85, 0x02, 0x05, 0x09, 0x19, 0x01, 0x29, 0x08, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x08, 0x81, 0x02, 0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x16, 0x01, 0xf8, 0x26, 0xff, 0x07, 0x75, 0x0c, 0x95, 0x02, 0x81, 0x06, 0x09, 0x38, 0x15, 0x81, 0x25, 0x7f, 0x75, 0x08, 0x95, 0x01, 0x81, 0x06, 0x05, 0x0c, 0x0a, 0x38, 0x02, 0x15, 0x81, 0x25, 0x7f, 0x75, 0x08, 0x95, 0x01, 0x81, 0x06, 0xc0, 0xc0, Device Found type: 04d8 003f path: \\?\HID#VID_04D8&PID_003F#6&42784ee&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030} serial_number: Manufacturer: Microchip Technology Inc. Product: Simple HID Device Demo Release: 2 Interface: 0 Usage (page): 0x1 (0xff00) Bus type: 1 (USB) Report Descriptor: (36 bytes) 0x06, 0x00, 0xff, 0x09, 0x01, 0xa1, 0x01, 0x19, 0x01, 0x29, 0x40, 0x15, 0x01, 0x25, 0x40, 0x75, 0x08, 0x95, 0x40, 0x81, 0x00, 0x19, 0x01, 0x29, 0x40, 0x15, 0x01, 0x25, 0x40, 0x75, 0x08, 0x95, 0x40, 0x91, 0x00, 0xc0, Manufacturer String: Microchip Technology Inc. Product String: Simple HID Device Demo Serial Number String: (0) Report Descriptor: (36 bytes) 0x06, 0x00, 0xff, 0x09, 0x01, 0xa1, 0x01, 0x19, 0x01, 0x29, 0x40, 0x15, 0x01, 0x25, 0x40, 0x75, 0x08, 0x95, 0x40, 0x81, 0x00, 0x19, 0x01, 0x29, 0x40, 0x15, 0x01, 0x25, 0x40, 0x75, 0x08, 0x95, 0x40, 0x91, 0x00, 0xc0, Device Found type: 04d8 003f path: \\?\HID#VID_04D8&PID_003F#6&42784ee&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030} serial_number: Manufacturer: Microchip Technology Inc. Product: Simple HID Device Demo Release: 2 Interface: 0 Usage (page): 0x1 (0xff00) Bus type: 1 (USB) Indexed String 1: Microchip Technology Inc. Unable to send a feature report. Unable to get a feature report: Get Input/Feature Report DeviceIoControl: (0x00000001) Incorrect function. waiting... Data read: 81 01 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c Press any key to continue . . . ```

Last portion with the test device (not exactly suitable for the test but this is probably the closest).

Button not pressed --> return 81 01

Device Found
  type: 04d8 003f
  path: \\?\HID#VID_04D8&PID_003F#6&42784ee&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer: Microchip Technology Inc.
  Product:      Simple HID Device Demo
  Release:      2
  Interface:    0
  Usage (page): 0x1 (0xff00)
  Bus type: 1 (USB)

Indexed String 1: Microchip Technology Inc.
Unable to send a feature report.
Unable to get a feature report: Get Input/Feature Report DeviceIoControl: (0x00000001) Incorrect function.
waiting...
Data read:
   81 01 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c
Press any key to continue . . .

Button pressed: return 81 00.

Device Found
  type: 04d8 003f
  path: \\?\HID#VID_04D8&PID_003F#6&42784ee&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer: Microchip Technology Inc.
  Product:      Simple HID Device Demo
  Release:      2
  Interface:    0
  Usage (page): 0x1 (0xff00)
  Bus type: 1 (USB)

Indexed String 1: Microchip Technology Inc.
Unable to send a feature report.
Unable to get a feature report: Get Input/Feature Report DeviceIoControl: (0x00000001) Incorrect function.
waiting...
Data read:
   81 00 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c
Press any key to continue . . .
mcuee commented 1 month ago

Using hidapitester.

MINGW64 /c/work/hid/hidapitester
$ diff -u Makefile Makefile_pr697
--- Makefile    2024-06-09 07:38:35.441954600 +0800
+++ Makefile_pr697      2024-09-29 11:11:18.637356000 +0800
@@ -4,7 +4,7 @@
 #

 # overide this with something like `HIDAPI_DIR=../hidapi-libusb make`
-HIDAPI_DIR ?= ../hidapi
+HIDAPI_DIR ?= ../hidapi_pr697

 # try to do some autodetecting
 UNAME := $(shell uname -s)

$ make clean
rm -f ../hidapi/windows/hid.o hidapitester.o
rm -f hidapitester.exe

$ make -f Makefile_pr697
gcc -I ../hidapi_pr697/hidapi -DHIDAPITESTER_VERSION=\"""v0.5""\" -c hidapitester.c -o hidapitester.o
gcc -I ../hidapi_pr697/hidapi -DHIDAPITESTER_VERSION=\"""v0.5""\" ../hidapi_pr697/windows/hid.o hidapitester.o -o hidapitester.exe -lsetupapi -Wl,--enable-auto-import -static-libgcc -static-libstdc++

$ ./hidapitester --list
046D/B021: Logitech - Logitech_Pebble
046D/B021: Logitech - Logitech_Pebble
8087/0A1E:  -
06CB/CD40: Microsoft - HIDI2C Device
06CB/CD40: Microsoft - HIDI2C Device
06CB/CD40: Microsoft - HIDI2C Device
06CB/CD40: Microsoft - HIDI2C Device
045E/0000:  -
045E/0000:  -
DEED/FEED: Acer Inc - Acer Airplane Mode Controller
045E/0000:  -
1EA7/0064: (Standard system devices) - 2.4G Mouse
1EA7/0064: (Standard system devices) - 2.4G Mouse
04D8/003F: Microchip Technology Inc. - Simple HID Device Demo

$ ./hidapitester --vidpid 04d8/003f --list-detail
04D8/003F: Microchip Technology Inc. - Simple HID Device Demo
  vendorId:      0x04D8
  productId:     0x003F
  usagePage:     0xFF00
  usage:         0x0001
  serial_number:
  interface:     0
  path: \\?\HID#VID_04D8&PID_003F#6&42784ee&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}

$ ./hidapitester --vidpid 04d8/003f --open --get-report-descriptor
Opening device, vid/pid: 0x04D8/0x003F
Report Descriptor:
 06 00 FF 09 01 A1 01 19 01 29 40 15 01 25 40 75 08 95 40 81 00 19 01 29 40 15 01 25 40 75 08 95
 40 91 00 C0
Closing device

$ ./hidapitester --vidpid 04d8/003f -l 64 --open --send-output 0x00,0x80
Opening device, vid/pid: 0x04D8/0x003F
Writing output report of 64-bytes...wrote 65 bytes:
 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Closing device

(Note--> toggle LED command with 0x80 -- this is working fine)
$ ./hidapitester --vidpid 04d8/003f --open --send-output 0x00,0x80
Opening device, vid/pid: 0x04D8/0x003F
Writing output report of 64-bytes...wrote 65 bytes:
 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Closing device

$ ./hidapitester --vidpid 04d8/003f --open --send-output 0x00,0x80
Opening device, vid/pid: 0x04D8/0x003F
Writing output report of 64-bytes...wrote 65 bytes:
 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Closing device

(Note--> Read button press status command with 0x81 -- this is working fine. 
Button Not pressed --> return 81 01
Button pressed --> return 81 00)
$ ./hidapitester --vidpid 04d8/003f --open --send-output 0x00,0x81 --read-input
Opening device, vid/pid: 0x04D8/0x003F
Writing output report of 64-bytes...wrote 65 bytes:
 00 81 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Reading up to 64-byte input report, 250 msec timeout...read 64 bytes:
 81 01 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C
 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C
Closing device

$ ./hidapitester --vidpid 04d8/003f --open --send-output 0x00,0x81 --read-input
Opening device, vid/pid: 0x04D8/0x003F
Writing output report of 64-bytes...wrote 65 bytes:
 00 81 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Reading up to 64-byte input report, 250 msec timeout...read 64 bytes:
 81 00 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C
 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C
Closing device
mcuee commented 1 month ago

@Youw

I am not sure if my tests can really catch anything, but there is no regression at least. I think it should be fine.

Youw commented 1 month ago

This is perfect, thanks!