In this section we examine the hardware abstraction layer: Halhal, a set of libraries built on Linux drivers. Just started to introduce why to add HAL to Android, the purpose is three, one, unified hardware call interface. Second, solve the GPL copyright issue. Third, for some special requirements. You can use the HAL code located in user space to assist the Linux driver in doing some work. HAL has the following main purposes: Unified hardware Call interface. Since HAL has a standard calling interface, HAL can be used to shield Linux drivers from complex, non-uniform interfaces, to solve the GPL protocol, and to address specific requirements. For some hardware, you may need access to some user-space resources, or work that is inconvenient in kernel space and special needs. In this case, you can use the HAL code located in the space to help Linux do some work.
The LED drivers implemented in this chapter include Linux drivers, HAL modules, service libraries, NDK programs, and Java programs.
The steps and principles for writing the HAL module are as follows.
The first step: defining structs and Macros writing HAL modules requires 3 very important structures, and in the first step you need to define two new structures.
The second step: The Open function of writing the HAL module is the entry point of the HAL module. In this example, the Led_device_open function is used. This function mainly does the following three work. Initializes the hw_device_t of the sub-structure. Open the device file. Initializes the register.
Step three: Define hw_module_methhods_t structure variables
Fourth step: Define the Hal_module_info_sym function
Fifth step: Write the close function of the HAL module and call the Close function when the HAL module is unloaded
Sixth step: Write the function that controls the LED
Hardware Abstraction Layer: HAL