The Android standard hardware driver is divided into two parts, one is the hardware driver running in the Linux kernel, and the other part is the hardware abstraction layer running in user space. Using this method, the system can be hardware-independent, but also protect the interests of some manufacturers. In Android from hardware to application: Step by Step 1--from zero to write the underlying hardware driver already has the steps to write the hardware driver to the Linux kernel, the next step is to see how to add hardware modules in the hardware abstraction layer and our kernel driver to interact, complete the hardware control.
Enter the Hardware/libhardware/include/hardware directory and create a new android_gpio.h:
#ifndef android_android_gpio_interface_h #define ANDROID_ANDROID_GPIO_INTERFACE_H #include
Where Set_val and Get_val are the API interfaces that HAL layers provide to upper-level applications.CD to Hardware/libhardware/modules directory, create a new Android_gpio directory, create a new ANDROID.C file inside:
#include To prevent the occurrence of Permission denied when called:Open the System/core/rootdir directory, open ueventd.rc add:
/dev/android_gpio 0666 Root root
Continue to add the Android.mk file in the Android_gpio directory:Local_path: = $ (call My-dir) include $ (clear_vars) Local_module_tags: = Optionallocal_prelink_module: = Falselocal_ Module_path: = $ (target_out_shared_libraries)/hwlocal_shared_libraries: = libloglocal_src_files: = android_ Gpio.clocal_module: = Android_gpio.defaultinclude $ (build_shared_library)
To compile the HAL layer:Mmm Hardware/libhardware/modules/android_gpio
If an error occurs, refer to:No command ' mmm ' found
There are no rules to create/lib/liblog.so
If successful, you can generate android_gpio.default.so
Install:out/target/product/generic/system/lib/hw/android_gpio.default.so
This is what we need the Hardware Abstraction Layer module, after this step is completed, and then go up, and finally complete the hardware call.
Android from hardware to application: Step-by-step 3-Hardware abstraction Layer access hardware driver