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 9*68b7054fSMatthias 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 17*68b7054fSMatthias Ringwald- Select WinUSB in the right pull down list 18a1a1af71SMatthias Ringwald- Select “Replace Driver” 19a1a1af71SMatthias Ringwald 20*68b7054fSMatthias Ringwald 21*68b7054fSMatthias Ringwald 22*68b7054fSMatthias RingwaldAfter the new driver was installed, your device is shown in the Device Manager with Device Provider 'libwdi' 23*68b7054fSMatthias Ringwald 24*68b7054fSMatthias Ringwald 25*68b7054fSMatthias Ringwald 2698918ebdSMatthias Ringwald## Visual Studio 2022 273cda7aedSMatthias Ringwald 2898918ebdSMatthias RingwaldVisual Studio can directly open the provided `port/windows-windows-h4-zephyr/CMakeLists.txt` and allows to compile and run all examples. 293cda7aedSMatthias Ringwald 3098918ebdSMatthias Ringwald## mingw64 3198918ebdSMatthias Ringwald 3298918ebdSMatthias RingwaldIt can also be compiles with a regular Unix-style toolchain like [mingw-w64](https://www.mingw-w64.org). 3398918ebdSMatthias 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.' 343cda7aedSMatthias Ringwald 35b5674ee2SMatthias RingwaldIn the MSYS2 shell, you can install everything with pacman: 363cda7aedSMatthias Ringwald 373cda7aedSMatthias Ringwald $ pacman -S git 389085f7a5SMatthias Ringwald $ pacman -S cmake 39b5674ee2SMatthias Ringwald $ pacman -S make 40b5674ee2SMatthias Ringwald $ pacman -S mingw-w64-x86_64-toolchain 419085f7a5SMatthias Ringwald $ pacman -S mingw-w64-x86_64-portaudio 423cda7aedSMatthias Ringwald $ pacman -S python 435b53c16eSMatthias Ringwald $ pacman -S winpty 443cda7aedSMatthias Ringwald 459085f7a5SMatthias Ringwald### Compilation with CMake 463cda7aedSMatthias Ringwald 479085f7a5SMatthias RingwaldWith mingw64-w64 installed, just go to the port/windows-h4 directory and use CMake as usual 483cda7aedSMatthias Ringwald 499085f7a5SMatthias Ringwald $ cd port/windows-h4 509085f7a5SMatthias Ringwald $ mkdir build 519085f7a5SMatthias Ringwald $ cd build 529085f7a5SMatthias Ringwald $ cmake .. 533cda7aedSMatthias Ringwald $ make 543cda7aedSMatthias Ringwald 550af1bfd9SMatthias RingwaldNote: When compiling with msys2-32 bit and/or the 32-bit toolchain, compilation fails 560af1bfd9SMatthias Ringwaldas `conio.h` seems to be mission. Please use msys2-64 bit with the 64-bit toolchain for now. 570af1bfd9SMatthias Ringwald 583cda7aedSMatthias Ringwald## Console Output 593cda7aedSMatthias Ringwald 60a1a1af71SMatthias 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: 61a1a1af71SMatthias Ringwald 623cda7aedSMatthias Ringwald $ winpty ./spp_and_le_counter.exe 63a1a1af71SMatthias Ringwald 64