xref: /btstack/port/qt-usb/README.md (revision 208aaac26d5f5e215b257db9f0b021a5f389d375)
1*208aaac2SMatthias Ringwald# BTstack Port for QT with USB Bluetooth Dongle
21b464e99SMatthias Ringwald
3*208aaac2SMatthias RingwaldUses libusb Library on macOS and Linux and WinUSB on Windows.
4*208aaac2SMatthias RingwaldWindows is supported with the MinGW Kit.
5*208aaac2SMatthias Ringwald
6*208aaac2SMatthias RingwaldWindows with MSVC or Embedded (bare metal) platforms not supported yet.
71b464e99SMatthias Ringwald
81b464e99SMatthias Ringwald## Compilation
91b464e99SMatthias Ringwald
10*208aaac2SMatthias RingwaldOn all platforms, you'll need Qt Python 3 installed.
11*208aaac2SMatthias RingwaldOn macOS/Linux [libusb-1.0](http://libusb.info) or higher is required, too.
121b464e99SMatthias Ringwald
131b464e99SMatthias RingwaldWhen everything is ready, you can open the provided CMakelists.txt project in Qt Creator and run any of the provided examples.
141b464e99SMatthias RingwaldSee Qt documentation on how to compile on the command line or with other IDEs
151b464e99SMatthias Ringwald
161b464e99SMatthias Ringwald## Environment Setup
171b464e99SMatthias Ringwald
18*208aaac2SMatthias Ringwald## Windows
19*208aaac2SMatthias Ringwald
20*208aaac2SMatthias 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.
21*208aaac2SMatthias Ringwald
22*208aaac2SMatthias RingwaldIt works like this:
23*208aaac2SMatthias Ringwald
24*208aaac2SMatthias Ringwald-  Download [Zadig](http://zadig.akeo.ie)
25*208aaac2SMatthias Ringwald-  Start Zadig
26*208aaac2SMatthias Ringwald-  Select Options -> “List all devices”
27*208aaac2SMatthias Ringwald-  Select USB Bluetooth dongle in the big pull down list
28*208aaac2SMatthias Ringwald-  Select WinUSB in the right pull down list
29*208aaac2SMatthias Ringwald-  Select “Replace Driver”
30*208aaac2SMatthias Ringwald
311b464e99SMatthias Ringwald### Linux
321b464e99SMatthias Ringwald
331b464e99SMatthias RingwaldOn Linux, the USB Bluetooth dongle is usually not accessible to a regular user. You can either:
341b464e99SMatthias Ringwald- run the examples as root
351b464e99SMatthias Ringwald- add a udev rule for your dongle to extend access rights to user processes
361b464e99SMatthias Ringwald
371b464e99SMatthias RingwaldTo add an udev rule, please create `/etc/udev/rules.d/btstack.rules` and add this
381b464e99SMatthias Ringwald
391b464e99SMatthias Ringwald	# Match all devices from CSR
401b464e99SMatthias Ringwald	SUBSYSTEM=="usb", ATTRS{idVendor}=="0a12", MODE="0666"
411b464e99SMatthias Ringwald
421b464e99SMatthias Ringwald	# Match DeLOCK Bluetooth 4.0 dongle
431b464e99SMatthias Ringwald	SUBSYSTEM=="usb", ATTRS{idVendor}=="0a5c", ATTRS{device}=="21e8", MODE="0666"
441b464e99SMatthias Ringwald
451b464e99SMatthias Ringwald	# Match Asus BT400
461b464e99SMatthias Ringwald	SUBSYSTEM=="usb", ATTRS{idVendor}=="0b05", ATTRS{device}=="17cb", MODE="0666"
471b464e99SMatthias Ringwald
481b464e99SMatthias Ringwald	# Match Laird BT860 / Cypress Semiconductor CYW20704A2
491b464e99SMatthias Ringwald	SUBSYSTEM=="usb", ATTRS{idVendor}=="04b4", ATTRS{device}=="f901", MODE="0666"
501b464e99SMatthias Ringwald
511b464e99SMatthias Ringwald### macOS
521b464e99SMatthias Ringwald
531b464e99SMatthias RingwaldOn macOS, the OS will try to use a plugged-in Bluetooth Controller if one is available.
541b464e99SMatthias RingwaldIt's best to to tell the OS to always use the internal Bluetooth Contoller.
551b464e99SMatthias Ringwald
561b464e99SMatthias RingwaldFor this, execute:
571b464e99SMatthias Ringwald
581b464e99SMatthias Ringwald    sudo nvram bluetoothHostControllerSwitchBehavior=never
591b464e99SMatthias Ringwald
601b464e99SMatthias Ringwaldand then reboot to activate the change.
611b464e99SMatthias Ringwald
621b464e99SMatthias RingwaldNote: if you get this error,
631b464e99SMatthias Ringwald
641b464e99SMatthias Ringwald	libusb: warning [darwin_open] USBDeviceOpen: another process has device opened for exclusive access
651b464e99SMatthias Ringwald	libusb: error [darwin_reset_device] ResetDevice: device not opened for exclusive access
661b464e99SMatthias Ringwald
671b464e99SMatthias Ringwaldand you didn't start another instance and you didn't assign the USB Controller to a virtual machine,
681b464e99SMatthias RingwaldmacOS uses the plugged-in Bluetooth Controller. Please configure NVRAM as explained and try again after a reboot.
691b464e99SMatthias Ringwald
701b464e99SMatthias Ringwald
711b464e99SMatthias Ringwald## Running the examples
721b464e99SMatthias Ringwald
731b464e99SMatthias RingwaldBTstack's HCI USB transport will try to find a suitable Bluetooth module and use it.
741b464e99SMatthias Ringwald
751b464e99SMatthias RingwaldOn start, BTstack will try to find a suitable Bluetooth module. It will also print the path to the packet log as well as the USB path.
761b464e99SMatthias Ringwald
771b464e99SMatthias Ringwald	$ ./le_counter
781b464e99SMatthias Ringwald	Packet Log: /tmp/hci_dump.pklg
791b464e99SMatthias Ringwald	BTstack counter 0001
801b464e99SMatthias Ringwald	USB Path: 06
811b464e99SMatthias Ringwald	BTstack up and running on 00:1A:7D:DA:71:13.
821b464e99SMatthias Ringwald
831b464e99SMatthias RingwaldIf you want to run multiple examples at the same time, it helps to fix the path to the used Bluetooth module by passing -u usb-path to the executable.
841b464e99SMatthias Ringwald
851b464e99SMatthias RingwaldExample running le_streamer and le_streamer_client in two processes, using Bluetooth dongles at USB path 6 and 4:
861b464e99SMatthias Ringwald
871b464e99SMatthias Ringwald	./le_streamer -u 6
881b464e99SMatthias Ringwald	Specified USB Path: 06
891b464e99SMatthias Ringwald	Packet Log: /tmp/hci_dump_6.pklg
901b464e99SMatthias Ringwald	USB Path: 06
911b464e99SMatthias Ringwald	BTstack up and running on 00:1A:7D:DA:71:13.
921b464e99SMatthias Ringwald	To start the streaming, please run the le_streamer_client example on other device, or use some GATT Explorer, e.g. LightBlue, BLExplr.
931b464e99SMatthias Ringwald
941b464e99SMatthias Ringwald	$ ./le_streamer_client -u 4
951b464e99SMatthias Ringwald	Specified USB Path: 04
961b464e99SMatthias Ringwald	Packet Log: /tmp/hci_dump_4.pklg
971b464e99SMatthias Ringwald	USB Path: 04
981b464e99SMatthias Ringwald	BTstack up and running on 00:1A:7D:DA:71:13.
991b464e99SMatthias Ringwald	Start scanning!
100