Write a C program to quickly test the hardware driver:
Create the Driver_test folder in the external folder under the Android source root directory:
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 <stdio.h> #include <stdlib.h> #include <fcntl.h> int main (int argc, char *argv []) { int fd; int val=0; Fd=open ("/dev/adrio", O_RDWR); if (fd<0) { printf ("Open device failed!\n"); Exit (1); } else { printf ("Open success! \ n "); } Write (fd,argv[1],1); Close (FD); return 0; }
Back to Android source root: Make Driver_test
You may initially be prompted with an error:
Host C + +: Libhost <= build/libs/host/pseudolocalize.cpp/bin/bash:g++: Command not found
Make: ***[OUT/HOST/LINUX-X86/OBJ/STATIC_LIBRARIES/LIBHOST_INTERMEDIATES/PSEUDOLOCALIZE.O] Error 127
Solve:
Sudo-i
Aptitude Install g++
sudo apt-get install build-essential
After the installation is complete, do the following: Make Driver_test
Final compilation Complete:
Install:out/target/product/generic/system/lib/libm.soinstall:out/target/product/generic/system/bin/driver_test
Copy the out/target/product/generic/system/bin/driver_test to the am335x file system and start Android
Run:
./driver_test 1 (then D1)
./driver_test 0 (then D1)
Tested successfully, this method can be used to quickly test the Linux kernel driver under Android
Android from hardware to application: Step by Step 2--run C program test hardware Driver