在Android User Mode 下,透過 libusb 操作 USB Device,如:送出 Control MSG 至 Device。
參考文件
Using Android in Industrial Automation
Technical Report
A student semester project at the University of Applied Sciences Northwestern Switzerland for the Institute of Automation
Authors: Manuel Di Cerbo, and Andreas Rudolf
Project principal: Matthias Meier ⃝
FHNW/IA, 29.01.2010
源碼下載
libusb-1.0.8.tar.bz2
檔案放置
libusb: /external/libusb-1.0.8/
lsusb: /external/lsusb/lsusb.c
編譯及安裝
- 新增 libusb-1.0.8/Android.mk
ifeq ($(TARGET_ARCH),arm)
LOCAL_PATH:= $(call my-dir)
subdirs := $(addprefix $(LOCAL_PATH)/,$(addsuffix /Android.mk, \
libusb \
))
include $(subdirs)
endif
- 新增 lsusb/Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := lsusb.c
LOCAL_MODULE := lsusb
LOCAL_C_INCLUDES += external/libusb-1.0.8/
LOCAL_SHARED_LIBRARIES := libc libusb
include $(BUILD_EXECUTABLE)
- 修改libusb-1.0.8/libusb/io.c
#ifndef TIMESPEC_TO_TIMEVAL
#define TIMESPEC_TO_TIMEVAL(tv, ts) \
do { \
(tv)->tv_sec = (ts)->tv_sec; \
(tv)->tv_usec = (ts)->tv_nsec / 1000; \
} while(0)
#endif /* end of TIMESPEC_TO_TIMEVAL */
為了解決
E: undefined reference to ‘TIMESPEC_TO_TIMEVAL’
S: defined TIMESPEC_TO_TIMEVAL macro in libusb/io.c
- 在 memory map(
/build/core/prelink-linux-arm.map 中加入 libusb.so(會依 platform 不同而有所不同)# extended system libraries
libusb.so 0xAE600000
libril.so 0xAE400000
如果沒有定義 memory address,在編譯時會產生底下的錯誤訊息:
E: build/tools/apriori/prelinkmap.c(137): library ’libusb.so’ not in prelink map
S: build/core/prelink-linux-arm.map
- 在 init.rc 的 on boot 節(session) 中加入 mount usbfs 的命令:
# usbfs
mkdir /proc/bus/usb 0771
mount usbfs none /proc/bus/usb -o devmode=0666
重新make & download image 試試看在 shell 底下 lsusb 能不能動囉!
沒有留言:
張貼留言