134fd36daSMatthias Ringwald# BTstack Port for Windows Systems using the WinUSB Driver 2a1a1af71SMatthias Ringwald 3c7558746SMatthias RingwaldThe Windows-WinUSB port uses the native run loop and WinUSB API to access a USB Bluetooth dongle. 4a1a1af71SMatthias Ringwald 598918ebdSMatthias RingwaldThe port provides both a regular Makefile as well as a CMake build file. It uses native Win32 APIs for file access and does not require the Cygwin or mingw64 build/runtine. All examples can also be build with Visual Studio 2022 (e.g. Community Edition). 698918ebdSMatthias Ringwald 73cda7aedSMatthias Ringwald## Access to Bluetooth USB Dongle with Zadig 83cda7aedSMatthias Ringwald 968b7054fSMatthias RingwaldTo allow WinUSB to access an USB Bluetooth dongle, you need to install a special device driver to make it accessible to user space processes. 10a1a1af71SMatthias Ringwald 11a1a1af71SMatthias RingwaldIt works like this: 123cda7aedSMatthias Ringwald 13c7558746SMatthias Ringwald- Download [Zadig](http://zadig.akeo.ie) 14c7558746SMatthias Ringwald- Start Zadig 15a1a1af71SMatthias Ringwald- Select Options -> “List all devices” 16a1a1af71SMatthias Ringwald- Select USB Bluetooth dongle in the big pull down list 1768b7054fSMatthias Ringwald- Select WinUSB in the right pull down list 18a1a1af71SMatthias Ringwald- Select “Replace Driver” 19a1a1af71SMatthias Ringwald 2068b7054fSMatthias Ringwald 2168b7054fSMatthias Ringwald 2268b7054fSMatthias RingwaldAfter the new driver was installed, your device is shown in the Device Manager with Device Provider 'libwdi' 2368b7054fSMatthias Ringwald 2468b7054fSMatthias Ringwald 2568b7054fSMatthias Ringwald 2698918ebdSMatthias Ringwald## Visual Studio 2022 273cda7aedSMatthias Ringwald 2805030944SMatthias RingwaldVisual Studio can directly open the provided `port/windows-winusb/CMakeLists.txt` and allows to compile and run all examples. 29*e52ff828SMatthias RingwaldFor this, the C++ CMake tools for Windows is required. They are part of the Desktop development with C++ workloads. 303cda7aedSMatthias Ringwald 3198918ebdSMatthias Ringwald## mingw64 3298918ebdSMatthias Ringwald 3398918ebdSMatthias RingwaldIt can also be compiles with a regular Unix-style toolchain like [mingw-w64](https://www.mingw-w64.org). 3498918ebdSMatthias Ringwaldmingw64-w64 is based on [MinGW](https://en.wikipedia.org/wiki/MinGW), which '...provides a complete Open Source programming tool set which is suitable for the development of native MS-Windows applications, and which do not depend on any 3rd-party C-Runtime DLLs.' 353cda7aedSMatthias Ringwald 36b5674ee2SMatthias RingwaldIn the MSYS2 shell, you can install everything with pacman: 373cda7aedSMatthias Ringwald 383cda7aedSMatthias Ringwald $ pacman -S git 399085f7a5SMatthias Ringwald $ pacman -S cmake 40b5674ee2SMatthias Ringwald $ pacman -S make 41b5674ee2SMatthias Ringwald $ pacman -S mingw-w64-x86_64-toolchain 429085f7a5SMatthias Ringwald $ pacman -S mingw-w64-x86_64-portaudio 433cda7aedSMatthias Ringwald $ pacman -S python 445b53c16eSMatthias Ringwald $ pacman -S winpty 453cda7aedSMatthias Ringwald 469085f7a5SMatthias Ringwald### Compilation with CMake 473cda7aedSMatthias Ringwald 489085f7a5SMatthias RingwaldWith mingw64-w64 installed, just go to the port/windows-h4 directory and use CMake as usual 493cda7aedSMatthias Ringwald 509085f7a5SMatthias Ringwald $ cd port/windows-h4 519085f7a5SMatthias Ringwald $ mkdir build 529085f7a5SMatthias Ringwald $ cd build 539085f7a5SMatthias Ringwald $ cmake .. 543cda7aedSMatthias Ringwald $ make 553cda7aedSMatthias Ringwald 560af1bfd9SMatthias RingwaldNote: When compiling with msys2-32 bit and/or the 32-bit toolchain, compilation fails 570af1bfd9SMatthias Ringwaldas `conio.h` seems to be mission. Please use msys2-64 bit with the 64-bit toolchain for now. 580af1bfd9SMatthias Ringwald 593cda7aedSMatthias Ringwald## Console Output 603cda7aedSMatthias Ringwald 61a1a1af71SMatthias RingwaldWhen running the examples in the MSYS2 shell, the console input (via btstack_stdin_support) doesn't work. It works in the older MSYS and also the regular CMD.exe environment. Another option is to install WinPTY and then start the example via WinPTY like this: 62a1a1af71SMatthias Ringwald 633cda7aedSMatthias Ringwald $ winpty ./spp_and_le_counter.exe 64a1a1af71SMatthias Ringwald 65