Android from hardware to application: Step by Step 3, step by step android
The Android standard hardware driver is divided into two parts: one is the hardware driver running in the Linux kernel, and the other is the hardware abstraction layer running in the user space. By using this method, the system can be unrelated to hardware and protect the interests of some vendors. From hardware to application in Android: Step by Step, step by step. 1. Write the underlying hardware driver from scratch to the Linux kernel, next, let's take a look at how to add a hardware module to the hardware abstraction layer to interact with our kernel driver to complete hardware control.
Go to the hardware/libhardware/include/hardware directory and create android_gpio.h:
#ifndef ANDROID_ANDROID_GPIO_INTERFACE_H #define ANDROID_ANDROID_GPIO_INTERFACE_H #include Set_val and get_val are the APIS provided by the upper-layer applications of the HAL layer.
Cd to the hardware/libhardware/modules directory, create the android_gpio directory, and create the android. c file in it:
#include To prevent calling with Permission denied:
Open the system/core/rootdir directory and open ueventd. rc to add:
/dev/android_gpio 0666 root root
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)
Compile the HAL layer:
mmm hardware/libhardware/modules/android_gpio
If an error occurs, refer:
No command 'mmm' found
You can create/lib/liblog. so without rules.
If successful, you can generate android_gpio.default.so
Install: out/target/product/generic/system/lib/hw/android_gpio.default.so
This is the hardware abstraction layer module we need. After this step is completed, we need to go up and finally complete the hardware call.