2021-05-31 15:26:07 +02:00
# BTstack Port for Windows Systems using the WinUSB Driver
2017-12-22 23:54:37 +01:00
2018-01-05 12:02:59 +01:00
The Windows-WinUSB port uses the native run loop and WinUSB API to access a USB Bluetooth dongle.
2017-12-22 23:54:37 +01:00
2022-06-13 22:39:53 +02:00
The 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).
2018-05-03 11:25:04 +02:00
## Access to Bluetooth USB Dongle with Zadig
2023-06-02 10:02:33 +02:00
To allow WinUSB to access an USB Bluetooth dongle, you need to install a special device driver to make it accessible to user space processes.
2017-12-22 23:54:37 +01:00
It works like this:
2018-05-03 11:25:04 +02:00
2018-01-05 12:02:59 +01:00
- Download [Zadig ](http://zadig.akeo.ie )
- Start Zadig
2017-12-22 23:54:37 +01:00
- Select Options -> “List all devices”
- Select USB Bluetooth dongle in the big pull down list
2023-06-02 10:02:33 +02:00
- Select WinUSB in the right pull down list
2017-12-22 23:54:37 +01:00
- Select “Replace Driver”
2023-06-02 10:02:33 +02:00

After the new driver was installed, your device is shown in the Device Manager with Device Provider 'libwdi'

2022-06-13 22:39:53 +02:00
## Visual Studio 2022
2023-09-06 15:48:06 +02:00
Visual Studio can directly open the provided `port/windows-winusb/CMakeLists.txt` and allows to compile and run all examples.
2024-03-05 18:00:27 +01:00
For this, the C++ CMake tools for Windows is required. They are part of the Desktop development with C++ workloads.
2018-05-03 11:25:04 +02:00
2022-06-13 22:39:53 +02:00
## mingw64
2018-05-03 11:25:04 +02:00
2022-06-13 22:39:53 +02:00
It can also be compiles with a regular Unix-style toolchain like [mingw-w64 ](https://www.mingw-w64.org ).
mingw64-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.'
2018-05-03 11:25:04 +02:00
2019-06-08 22:48:30 +02:00
In the MSYS2 shell, you can install everything with pacman:
2018-05-03 11:25:04 +02:00
$ pacman -S git
2022-11-21 14:29:59 +01:00
$ pacman -S cmake
2019-06-08 22:48:30 +02:00
$ pacman -S make
$ pacman -S mingw-w64-x86_64-toolchain
2022-11-21 14:29:59 +01:00
$ pacman -S mingw-w64-x86_64-portaudio
2018-05-03 11:25:04 +02:00
$ pacman -S python
2018-05-03 11:29:38 +02:00
$ pacman -S winpty
2018-05-03 11:25:04 +02:00
2022-11-21 14:29:59 +01:00
### Compilation with CMake
2018-05-03 11:25:04 +02:00
2022-11-21 14:29:59 +01:00
With mingw64-w64 installed, just go to the port/windows-h4 directory and use CMake as usual
2018-05-03 11:25:04 +02:00
2022-11-21 14:29:59 +01:00
$ cd port/windows-h4
$ mkdir build
$ cd build
$ cmake ..
2018-05-03 11:25:04 +02:00
$ make
2020-03-18 10:26:22 +01:00
Note: When compiling with msys2-32 bit and/or the 32-bit toolchain, compilation fails
as `conio.h` seems to be mission. Please use msys2-64 bit with the 64-bit toolchain for now.
2018-05-03 11:25:04 +02:00
## Console Output
2017-12-22 23:54:37 +01:00
When 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:
2018-05-03 11:25:04 +02:00
$ winpty ./spp_and_le_counter.exe
2017-12-22 23:54:37 +01:00