Android from hardware to application: Step-by-step 3-Hardware abstraction Layer access hardware driver

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.