Android from hardware to application: Step by Step 2 -- run the C program to test the hardware driver
Compile a C program to quickly test the hardware driver:
Create the driver_test folder in the external Folder under the root directory of the Android source code:
Cd external
Mkdir driver_test
Cd driver_test
Create Android. mk:
LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE_TAGS := optionalLOCAL_MODULE := driver_testLOCAL_SRC_FILES := driver_test.cinclude $(BUILD_EXECUTABLE)
Create driver_test.c:
#include
#include
#include
int main(int argc, char *argv[]) { int fd; int val=0; fd=open(/dev/AdrIO,O_RDWR); if(fd<0) { printf(open device failed !); exit(1); } else { printf(open success ! ); } write(fd,argv[1],1); close(fd); return 0; }
Go back to the Android source code root directory: make driver_test
An error may be prompted at first:
Host c ++: libhost <= build/libs/host/pseudo dolocalize. cpp/bin/bash: g ++: Command not found
Make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libhost_intermediates/pseudo localize. o] Error 127
Solution:
Sudo-I
Aptitude install g ++
Sudo apt-get install build-essential
After installation, run make driver_test.
The final compilation is complete:
Install: out/target/product/generic/system/lib/libm.soInstall: out/target/product/generic/system/bin/driver_test
Copy out/target/product/generic/system/bin/driver_test to the AM335X file system and start Android
Run:
./Driver_test 1 (D1 on at this moment)
./Driver_test 0 (D1 off at this time)