Difference between revisions of "Transclusion: Debian: CL-SOM-iMX7: Bluetooth"

From Compulab Mediawiki
Jump to: navigation, search
(Bluez5 & PulseAudio)
imported>Uri.mashiach
 
(One intermediate revision by one other user not shown)
Line 5: Line 5:
 
Make sure that the Bluetooth driver is loaded:
 
Make sure that the Bluetooth driver is loaded:
 
<pre>
 
<pre>
root@cl-rootfs:~# lsmod | grep btwilink
+
root@cl-debian:~# lsmod | grep hci_uart
btwilink                3822 0
+
hci_uart              10445 1
 
</pre>
 
</pre>
 
The Bluetooth driver can be loaded manually:
 
The Bluetooth driver can be loaded manually:
 
<pre>
 
<pre>
root@cl-rootfs:~# modprobe btwilink
+
root@cl-rootfs:~# modprobe hci_uart
 
</pre>
 
</pre>
  
Line 16: Line 16:
 
<pre>
 
<pre>
 
root@cl-rootfs:~# hciconfig hci0 -a
 
root@cl-rootfs:~# hciconfig hci0 -a
hci0:  Type: BR/EDR Bus: UART
+
hci0:  Type: Primary Bus: UART
         BD Address: 74:DA:EA:F9:CE:E3 ACL MTU: 1021:6  SCO MTU: 180:4
+
         BD Address: 3C:A3:08:A8:03:B9 ACL MTU: 1021:6  SCO MTU: 180:4
 
         UP RUNNING  
 
         UP RUNNING  
         RX bytes:636 acl:0 sco:0 events:39 errors:0
+
         RX bytes:746 acl:0 sco:0 events:49 errors:0
         TX bytes:1234 acl:0 sco:0 commands:39 errors:0
+
         TX bytes:3441 acl:0 sco:0 commands:49 errors:0
 
         Features: 0xff 0xfe 0x2d 0xfe 0xdb 0xff 0x7b 0x87
 
         Features: 0xff 0xfe 0x2d 0xfe 0xdb 0xff 0x7b 0x87
 
         Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3  
 
         Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3  
 
         Link policy: RSWITCH HOLD SNIFF  
 
         Link policy: RSWITCH HOLD SNIFF  
 
         Link mode: SLAVE ACCEPT  
 
         Link mode: SLAVE ACCEPT  
         Name: 'BlueZ 5.36'
+
         Name: 'cl-debian'
         Class: 0x000000
+
         Class: 0x0c0000
         Service Classes: Unspecified
+
         Service Classes: Rendering, Capturing
 
         Device Class: Miscellaneous,  
 
         Device Class: Miscellaneous,  
 
         HCI Version: 4.1 (0x7)  Revision: 0x0
 
         HCI Version: 4.1 (0x7)  Revision: 0x0
Line 42: Line 42:
 
root@cl-rootfs:~# hcitool scan
 
root@cl-rootfs:~# hcitool scan
 
Scanning ...
 
Scanning ...
</pre>
 
 
==== Bluez5 & PulseAudio ====
 
Debian stretch/sid is using BlueZ 5 and PluseAudio 5, which are fairly new.<br>
 
BlueZ 5 dropped support for alsa, so the solution for now is to use PulseAudio.<br>
 
PulseAudio 5 only supports the A2DP profile and not HSP/HFP. <br>
 
* Software to install {{filename|pulseaudio}}, {{filename|pulseaudio-module-bluetooth}}
 
{{Note|{{filename|debian-image.tar.bz2}} has all these packages pre-installed. Continue to the [[#Start PulseAudio | Start PulseAudio]] section if you use this root filesystem.}}
 
===== Install and configure PulseAudio =====
 
<pre>
 
root@cl-rootfs:~# apt-get install --no-install-recommends pulseaudio pulseaudio-module-bluetooth
 
</pre>
 
* Create a systemd service for running pulseaudio as the pulse user.
 
<pre>
 
root@cl-rootfs:~# cat << eof > /etc/systemd/system/pulseaudio.service
 
[Unit]
 
Description=Pulse Audio
 
 
[Service]
 
Type=simple
 
ExecStart=/usr/bin/pulseaudio --system --disallow-exit --disable-shm
 
 
[Install]
 
WantedBy=multi-user.target
 
eof
 
 
root@cl-rootfs:~# chown pulse:pulse /etc/systemd/system/pulseaudio.service
 
</pre>
 
 
* Create a dbus configuration file for running pulseaudio. Give the pulse user permission to use Bluetooth.
 
<pre>
 
root@cl-rootfs:~# cat << eof > /etc/dbus-1/system.d/pulseaudio-bluetooth.conf
 
<busconfig>
 
 
  <policy user="pulse">
 
    <allow send_destination="org.bluez"/>
 
  </policy>
 
 
</busconfig>
 
eof
 
 
root@cl-rootfs:~# chmod 0666 /etc/dbus-1/system.d/pulseaudio-bluetooth.conf
 
</pre>
 
* Paste the following lines to the end of /etc/pulse/system.pa:
 
<pre>
 
root@cl-rootfs:~# cat << eof >> /etc/pulse/system.pa
 
### Automatically load driver modules for Bluetooth hardware
 
.ifexists module-bluetooth-policy.so
 
load-module module-bluetooth-policy
 
.endif
 
 
.ifexists module-bluetooth-discover.so
 
load-module module-bluetooth-discover
 
.endif
 
eof
 
</pre>
 
* Create {{filename|/var/run/pulse/.config/pulse}} directory. Change its ownership.
 
<pre>
 
root@cl-rootfs:~# mkdir -p /var/run/pulse/.config/pulse
 
root@cl-rootfs:~# chown -R pulse:pulse /var/run/pulse
 
</pre>
 
* Make the root belong to the pulse-access,audio groups
 
<pre>
 
root@cl-rootfs:~# usermod -a -G pulse-access,audio root
 
</pre>
 
 
===== Start PulseAudio =====
 
* Start PulseAudio service
 
<pre>
 
root@cl-rootfs:~# systemctl daemon-reload
 
root@cl-rootfs:~# systemctl start pulseaudio.service
 
</pre>
 
* Make sure that the service is active, running and reports on no errors.
 
<pre>
 
root@cl-rootfs:~# systemctl status pulseaudio.service
 
  Loaded: loaded (/etc/systemd/system/pulseaudio.service; disabled)
 
  Active: active (running) since Mon 2015-07-20 12:00:13 UTC; 1min 34s ago
 
Main PID: 805 (pulseaudio)
 
  CGroup: /system.slice/pulseaudio.service
 
          └─805 /usr/bin/pulseaudio --system --disallow-exit --disable-shm
 
</pre>
 
 
===== Bluez5 pairing =====
 
PulseAudio 5.x supports A2DP per default.<br>
 
Make sure the following packages are installed:
 
pulseaudio pulseaudio-module-bluetooth pulseaudio-utils, bluez, bluez-tools.
 
{{Note|Without {{filename|pulseaudio-module-bluetooth}} you won't be able to connect after the next pairing and you won't get any usable error messages.}}
 
 
* Start the Bluetooth system:
 
<pre>
 
root@cl-rootfs:~# systemctl start bluetooth
 
</pre>
 
Now we can use the {{cmd|bluetoothctl}} command line utility to pair and connect. Run
 
<pre>
 
root@cl-rootfs:~# bluetoothctl
 
[bluetooth]#
 
</pre>
 
to be greeted by its internal command prompt.Then enter:
 
<pre>
 
[bluetooth]# power on
 
[bluetooth]# agent on
 
[bluetooth]# default-agent
 
[bluetooth]# scan
 
</pre>
 
Now make sure that your headset is in pairing mode. It should be discovered shortly. For example,
 
<pre>
 
[NEW] Device 00:07:A4:F2:B3:CB Motorola HT820
 
</pre>
 
shows a device that calls itself "Motorola HT820" and has MAC address 00:07:A4:F2:B3:CB.
 
We will now use that MAC address to initiate the pairing:
 
<pre>
 
[bluetooth]# pair 00:07:A4:F2:B3:CB
 
</pre>
 
After pairing, you also need to explicitly connect the device:
 
<pre>
 
[bluetooth]# connect 00:07:A4:F2:B3:CB
 
</pre>
 
If everything works correctly, you now have a separate output device in PulseAudio.<br>
 
You can now disable scanning again and exit the program:
 
<pre>
 
[bluetooth]# scan off
 
[bluetooth]# exit
 
</pre>
 
 
===== Playback using PulseAudio =====
 
{{Note|Next examples assume that the device mac address is '''00_07_A4_F2_B3_CB'''}}
 
* Show the PulseAudio device
 
<pre>
 
root@cl-rootfs:~# pactl list cards  | awk '/00_07_A4_F2_B3_CB/' RS=""
 
Card #1                                                                                                                                                                   
 
        Name: bluez_card.00_07_A4_F2_B3_CB                                                                                                                                 
 
        Driver: module-bluez5-device.c                                                                                                                                     
 
        Owner Module: 13                                                                                                                                                   
 
        Properties:                                                                                                                                                       
 
                device.description = "Motorola HT820"                                                                                                                     
 
                device.string = "00:07:A4:F2:B3:CB"                                                                                                                       
 
                device.api = "bluez"                                                                                                                                       
 
                device.class = "sound"                                                                                                                                     
 
                device.bus = "bluetooth"                                                                                                                                   
 
                device.form_factor = "headset"                                                                                                                             
 
                bluez.path = "/org/bluez/hci0/dev_00_07_A4_F2_B3_CB"                                                                                                       
 
                bluez.class = "0x240404"                                                                                                                                   
 
                bluez.alias = "Motorola HT820"                                                                                                                             
 
                device.icon_name = "audio-headset-bluetooth"                                                                                                               
 
                device.intended_roles = "phone"                                                                                                                           
 
        Profiles:                                                                                                                                                         
 
                headset_head_unit: Headset Head Unit (HSP/HFP) (sinks: 1, sources: 1, priority: 20, available: no)
 
                a2dp_sink: High Fidelity Playback (A2DP Sink) (sinks: 1, sources: 0, priority: 10, available: yes)
 
                off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
 
        Active Profile: a2dp_sink
 
        Ports:
 
                headset-output: Headset (priority: 0, latency offset: 0 usec)
 
                        Part of profile(s): headset_head_unit, a2dp_sink
 
                headset-input: Headset (priority: 0, latency offset: 0 usec, not available)
 
                        Part of profile(s): headset_head_unit
 
</pre>
 
:* Make sure the active card profile is a2dp_sink. Otherwise switch to it:
 
<pre>
 
# pactl set-card-profile 1 a2dp_sink
 
</pre>
 
:* Show the PulseAudio sink
 
<pre>
 
root@cl-rootfs:~# pactl list sinks | awk '/00_07_A4_F2_B3_CB/' RS=""
 
Sink #1
 
        State: SUSPENDED
 
        Name: bluez_sink.00_07_A4_F2_B3_CB
 
        Description: Motorola HT820
 
        Driver: module-bluez5-device.c
 
        Sample Specification: s16le 2ch 48000Hz
 
        Channel Map: front-left,front-right
 
        Owner Module: 13
 
        Mute: no
 
        Volume: front-left: 65536 / 100% / 0.00 dB,  front-right: 65536 / 100% / 0.00 dB
 
                balance 0.00
 
        Base Volume: 65536 / 100% / 0.00 dB
 
        Monitor Source: bluez_sink.00_07_A4_F2_B3_CB.monitor
 
        Latency: 0 usec, configured 0 usec
 
        Flags: HARDWARE DECIBEL_VOLUME LATENCY
 
        Properties:
 
                bluetooth.protocol = "a2dp_sink"
 
                device.description = "Motorola HT820"
 
                device.string = "00:07:A4:F2:B3:CB"
 
                device.api = "bluez"
 
                device.class = "sound"
 
                device.bus = "bluetooth"
 
                device.form_factor = "headset"
 
                bluez.path = "/org/bluez/hci0/dev_00_07_A4_F2_B3_CB"
 
                bluez.class = "0x240404"
 
                bluez.alias = "Motorola HT820"
 
                device.icon_name = "audio-headset-bluetooth"
 
                device.intended_roles = "phone"
 
        Ports:
 
                headset-output: Headset (priority: 0)
 
        Active Port: headset-output
 
        Formats:
 
                pcm
 
</pre>
 
:* Play sound using {{filename|paplay}}. Example:
 
<pre>
 
root@cl-rootfs:~# paplay -d bluez_sink.00_07_A4_F2_B3_CB /path/to/<audio-file.wav>
 
 
</pre>
 
</pre>

Latest revision as of 16:43, 4 December 2018

CL-SOM-iMX7 features Bluetooth 4.1 BLE interface, implemented with a TI WiLink8 Combo module.

Host Controller Interface (HCI) Initialization

  • HCI requires no user interaction for being configured. The driver gets loaded automatically unless this option has been disabled by putting a black list rule for this device.

Make sure that the Bluetooth driver is loaded:

root@cl-debian:~# lsmod | grep hci_uart
hci_uart               10445  1

The Bluetooth driver can be loaded manually:

root@cl-rootfs:~# modprobe hci_uart
  • HCI device configuration utility can be run to retrieve detailed information about the Bluetooth interfaces:
root@cl-rootfs:~# hciconfig hci0 -a
hci0:   Type: Primary  Bus: UART
        BD Address: 3C:A3:08:A8:03:B9  ACL MTU: 1021:6  SCO MTU: 180:4
        UP RUNNING 
        RX bytes:746 acl:0 sco:0 events:49 errors:0
        TX bytes:3441 acl:0 sco:0 commands:49 errors:0
        Features: 0xff 0xfe 0x2d 0xfe 0xdb 0xff 0x7b 0x87
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
        Link policy: RSWITCH HOLD SNIFF 
        Link mode: SLAVE ACCEPT 
        Name: 'cl-debian'
        Class: 0x0c0000
        Service Classes: Rendering, Capturing
        Device Class: Miscellaneous, 
        HCI Version: 4.1 (0x7)  Revision: 0x0
        LMP Version: 4.1 (0x7)  Subversion: 0xac03
        Manufacturer: Texas Instruments Inc. (13)
  • If the HCI device is not running, use the below command to enable the HCI device:
root@cl-rootfs:~# hciconfig hci0 up
  • HCI Inquire remote devices.
root@cl-rootfs:~# hcitool scan
Scanning ...