Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux 程式設計 >> Linux 程式設計

在 ARM 開發板上使用 USB 藍牙適配器

關鍵字:dbus、bluez-lib、bluez-utils、USB 藍牙、ARM。

操作環境

主機端為 Windows XP 上的 VMware 虛擬機跑 Ubuntu 10.10,開發板為 OK6410,檔案系統 yaffs2,交叉編譯器 arm-linux-gcc 4.3.2,藍牙採 USB 適配器(同一支在 PC 的 Ubuntu 下已測試可用)。

環境選擇上老實說一句:若手邊有 Red Hat 或 Fedora,建議優先使用,Ubuntu 在這條路上要處理的相依問題確實偏多。

一、內核配置

先 make menuconfig,把藍牙相關項目打開:

[*] Networking support --->
    <*>   Bluetooth subsystem support --->   // 藍牙子系統,必選
        <*>   L2CAP protocol support           // 邏輯鏈路控制與適配協議
        <*>   SCO links support                // 藍牙語音與耳機支援
        <*>   RFCOMM protocol support          // 面向流的傳輸協議,撥號網路等
        [*]   RFCOMM TTY support
        <*>   BNEP protocol support            // 藍牙網路封裝協議,自組網
        [*]   Multicast filter support
        [*]   Protocol filter support
        <*>   HIDP protocol support            // 基本輸入裝置協議

    Bluetooth device drivers --->
        <*>   HCI USB driver                   // USB 藍牙模組,必選
        <M>   HCI UART driver                  // 串口、CF 卡或 PCMCIA 藍牙
        <*>   HCI BlueFRITZ! USB driver
        <*>   HCI VHCI (Virtual HCI device) driver

其中 HCI USB driver 是 USB 適配器能否被辨識的關鍵,務必編進內核或編為模組並確實載入。

二、開機後的檢測

插入適配器,序列埠應能看到類似以下的訊息,代表 USB Already 抓到裝置(idVendor=0a12、idProduct=0001 是常見的 CSR 晶片):

usb 1-1: new full speed USB device using s3c2410-ohci and address 2
usb 1-1: New USB device found, idVendor=0a12, idProduct=0001
usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0

接著用 hciconfig 查看藍牙裝置:

# hciconfig
hci0:   Type: USB
        BD Address: 00:00:00:00:00:00 ACL MTU: 0:0 SCO MTU: 0:0
        DOWN
        RX bytes:0 acl:0 sco:0 events:0 errors:0
        TX bytes:0 acl:0 sco:0 commands:0 errors:0

狀態顯示 DOWN 是正常的,尚未啟用而已。執行 hciconfig hci0 up 拉起裝置後,BD Address 應該會顯示真正的 MAC;若仍是全 0,通常表示韌體或時鐘沒有正確載入,此時回頭確認內核的 HCI USB driver 與 USB 控制器(OHCI)是否都開啟,會比一直重插裝置有效。

三、使用者空間的必備套件

內核只是基礎,真正做事的是 bluez:bluez-lib 提供函式庫,bluez-utils 提供 hciconfig、hcitool、sdptool 等命令列工具,dbus 則是 bluez4 之後元件間溝通所依賴的訊息匯流排。交叉編譯時三者都要一併編出並部署到板子的 rootfs,缺任何一項都會在執行階段才暴露問題。

Copyright © Linux教程網 All Rights Reserved