xref: /btstack/port/qt-usb/README.md (revision 1b464e99afd70ddaf6b75be1ba7cc563a5f5dfd8)
1*1b464e99SMatthias Ringwald# BTstack Port for QT with libusb Library (Mac/Linux)
2*1b464e99SMatthias Ringwald
3*1b464e99SMatthias RingwaldWindows or Embedded (bare metal) platforms not supported yet.
4*1b464e99SMatthias Ringwald
5*1b464e99SMatthias Ringwald## Compilation
6*1b464e99SMatthias Ringwald
7*1b464e99SMatthias RingwaldYou'll need Qt and [libusb-1.0](http://libusb.info) or higher to be
8*1b464e99SMatthias Ringwaldinstalled.
9*1b464e99SMatthias Ringwald
10*1b464e99SMatthias RingwaldWhen everything is ready, you can open the provided CMakelists.txt project in Qt Creator and run any of the provided examples.
11*1b464e99SMatthias RingwaldSee Qt documentation on how to compile on the command line or with other IDEs
12*1b464e99SMatthias Ringwald
13*1b464e99SMatthias Ringwald## Environment Setup
14*1b464e99SMatthias Ringwald
15*1b464e99SMatthias Ringwald### Linux
16*1b464e99SMatthias Ringwald
17*1b464e99SMatthias RingwaldOn Linux, the USB Bluetooth dongle is usually not accessible to a regular user. You can either:
18*1b464e99SMatthias Ringwald- run the examples as root
19*1b464e99SMatthias Ringwald- add a udev rule for your dongle to extend access rights to user processes
20*1b464e99SMatthias Ringwald
21*1b464e99SMatthias RingwaldTo add an udev rule, please create `/etc/udev/rules.d/btstack.rules` and add this
22*1b464e99SMatthias Ringwald
23*1b464e99SMatthias Ringwald	# Match all devices from CSR
24*1b464e99SMatthias Ringwald	SUBSYSTEM=="usb", ATTRS{idVendor}=="0a12", MODE="0666"
25*1b464e99SMatthias Ringwald
26*1b464e99SMatthias Ringwald	# Match DeLOCK Bluetooth 4.0 dongle
27*1b464e99SMatthias Ringwald	SUBSYSTEM=="usb", ATTRS{idVendor}=="0a5c", ATTRS{device}=="21e8", MODE="0666"
28*1b464e99SMatthias Ringwald
29*1b464e99SMatthias Ringwald	# Match Asus BT400
30*1b464e99SMatthias Ringwald	SUBSYSTEM=="usb", ATTRS{idVendor}=="0b05", ATTRS{device}=="17cb", MODE="0666"
31*1b464e99SMatthias Ringwald
32*1b464e99SMatthias Ringwald	# Match Laird BT860 / Cypress Semiconductor CYW20704A2
33*1b464e99SMatthias Ringwald	SUBSYSTEM=="usb", ATTRS{idVendor}=="04b4", ATTRS{device}=="f901", MODE="0666"
34*1b464e99SMatthias Ringwald
35*1b464e99SMatthias Ringwald### macOS
36*1b464e99SMatthias Ringwald
37*1b464e99SMatthias RingwaldOn macOS, the OS will try to use a plugged-in Bluetooth Controller if one is available.
38*1b464e99SMatthias RingwaldIt's best to to tell the OS to always use the internal Bluetooth Contoller.
39*1b464e99SMatthias Ringwald
40*1b464e99SMatthias RingwaldFor this, execute:
41*1b464e99SMatthias Ringwald
42*1b464e99SMatthias Ringwald    sudo nvram bluetoothHostControllerSwitchBehavior=never
43*1b464e99SMatthias Ringwald
44*1b464e99SMatthias Ringwaldand then reboot to activate the change.
45*1b464e99SMatthias Ringwald
46*1b464e99SMatthias RingwaldNote: if you get this error,
47*1b464e99SMatthias Ringwald
48*1b464e99SMatthias Ringwald	libusb: warning [darwin_open] USBDeviceOpen: another process has device opened for exclusive access
49*1b464e99SMatthias Ringwald	libusb: error [darwin_reset_device] ResetDevice: device not opened for exclusive access
50*1b464e99SMatthias Ringwald
51*1b464e99SMatthias Ringwaldand you didn't start another instance and you didn't assign the USB Controller to a virtual machine,
52*1b464e99SMatthias RingwaldmacOS uses the plugged-in Bluetooth Controller. Please configure NVRAM as explained and try again after a reboot.
53*1b464e99SMatthias Ringwald
54*1b464e99SMatthias Ringwald
55*1b464e99SMatthias Ringwald## Running the examples
56*1b464e99SMatthias Ringwald
57*1b464e99SMatthias RingwaldBTstack's HCI USB transport will try to find a suitable Bluetooth module and use it.
58*1b464e99SMatthias Ringwald
59*1b464e99SMatthias 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.
60*1b464e99SMatthias Ringwald
61*1b464e99SMatthias Ringwald	$ ./le_counter
62*1b464e99SMatthias Ringwald	Packet Log: /tmp/hci_dump.pklg
63*1b464e99SMatthias Ringwald	BTstack counter 0001
64*1b464e99SMatthias Ringwald	USB Path: 06
65*1b464e99SMatthias Ringwald	BTstack up and running on 00:1A:7D:DA:71:13.
66*1b464e99SMatthias Ringwald
67*1b464e99SMatthias 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.
68*1b464e99SMatthias Ringwald
69*1b464e99SMatthias RingwaldExample running le_streamer and le_streamer_client in two processes, using Bluetooth dongles at USB path 6 and 4:
70*1b464e99SMatthias Ringwald
71*1b464e99SMatthias Ringwald	./le_streamer -u 6
72*1b464e99SMatthias Ringwald	Specified USB Path: 06
73*1b464e99SMatthias Ringwald	Packet Log: /tmp/hci_dump_6.pklg
74*1b464e99SMatthias Ringwald	USB Path: 06
75*1b464e99SMatthias Ringwald	BTstack up and running on 00:1A:7D:DA:71:13.
76*1b464e99SMatthias Ringwald	To start the streaming, please run the le_streamer_client example on other device, or use some GATT Explorer, e.g. LightBlue, BLExplr.
77*1b464e99SMatthias Ringwald
78*1b464e99SMatthias Ringwald	$ ./le_streamer_client -u 4
79*1b464e99SMatthias Ringwald	Specified USB Path: 04
80*1b464e99SMatthias Ringwald	Packet Log: /tmp/hci_dump_4.pklg
81*1b464e99SMatthias Ringwald	USB Path: 04
82*1b464e99SMatthias Ringwald	BTstack up and running on 00:1A:7D:DA:71:13.
83*1b464e99SMatthias Ringwald	Start scanning!
84