Two structural bodies related to Hal hw_module_t, hw_device_t
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/2E/E7/wKioL1OdnwHhhqtaAAJyyuX6_Ig195.jpg "title=" Jiegoutti.png "alt=" Wkiol1odnwhhhqtaaajyyux6_ig195.jpg "/>
I. The relationship between JNI and Hal
TIP: A framework of relationships between several app,jni,hal,framework
650) this.width=650; "Src=" https://note.wiz.cn/unzip/232b0826-d65c-4c92-bde7-64832286df9e/ Bd291518-ffe1-45de-8ddc-4994486b6e16.1519/index_files/9b7935a1-70ee-46de-a041-27b457259b43.jpg "alt=" 9b7935a1-70ee-46de-a041-27b457259b43.jpg "/> This article uses the framework of the second framework of the preparation, their relationship is as follows;
It can be seen that JNI mainly uses pmodule and pdevice to get the variables in the HAL to manipulate the HAL layer
650) this.width=650; "Src=" https://note.wiz.cn/unzip/232b0826-d65c-4c92-bde7-64832286df9e/ Bd291518-ffe1-45de-8ddc-4994486b6e16.1519/index_files/feffb976-ff92-4b54-b9e5-a516bbea88ce.jpg "alt=" Feffb976-ff92-4b54-b9e5-a516bbea88ce.jpg "/>
Second, JNI operation Hal
get HAL layer:1, jni gets the module and device object of the HAL layer
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/2E/E6/wKiom1OdnRWSqp97AAIS2EBu2Ms194.jpg "title=" Jniduix.png "alt=" Wkiom1odnrwsqp97aais2ebu2ms194.jpg "/>
Operation Hal layer :2, JNI operation HAL Layer
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/2E/E7/wKioL1OdnfCAMozZAACDnE7uZxY132.jpg "style=" float: none; "title=" Closeled.png "alt=" Wkiol1odnfcamozzaacdne7uzxy132.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/2E/E6/wKiom1Odnh6A27x6AAB0TUBM3XA714.jpg "style=" float: none; "title=" Ledoff.png "alt=" Wkiom1odnh6a27x6aab0tubm3xa714.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/2E/E7/wKioL1OdnfCAMfp_AAB5H95wXpg587.jpg "style=" float: none; "title=" Ledon.png "alt=" Wkiol1odnfcamfp_aab5h95wxpg587.jpg "/>
JNI Operation HAL Complete code reference [Android Bottom]jni Get custom class function written to compare
Iii. Writing of Hal
Writing HAL Note points (Notes section)
1, Hal's. h file writing, own hardware custom modules and device writing, led for example 650) this.width=650; "Src=" https://note.wiz.cn/unzip/ 232b0826-d65c-4c92-bde7-64832286df9e/bd291518-ffe1-45de-8ddc-4994486b6e16.1519/index_files/ 55541905-052a-4490-84e2-37770b5dca1a.png "style=" border:0px;font-size:10.5pt;line-height:1.5; "alt=" 55541905-052a-4490-84e2-37770b5dca1a.png "/>
2. Steps for writing the. c File of Hal
Write the two cores of the HAL
structure of a structural body hw_module_t
650) this.width=650; "Src=" https://note.wiz.cn/unzip/232b0826-d65c-4c92-bde7-64832286df9e/ Bd291518-ffe1-45de-8ddc-4994486b6e16.1519/index_files/8c84b207-21b3-4e22-985f-3bc8e49415ed.png "style=" border:0 px; "alt=" 8c84b207-21b3-4e22-985f-3bc8e49415ed.png "/>
An open function in a hw_module_methods_t;
650) this.width=650; "Src=" https://note.wiz.cn/unzip/232b0826-d65c-4c92-bde7-64832286df9e/ Bd291518-ffe1-45de-8ddc-4994486b6e16.1519/index_files/104c0a85-815e-488c-9bfa-1d69ef768f8d.png "style=" border:0 px;font-size:10.5pt;line-height:1.5; "alt=" 104c0a85-815e-488c-9bfa-1d69ef768f8d.png "/>
Hal Authoring Steps
First step:hal everything starts with the HMI
650) this.width=650; "Src=" https://note.wiz.cn/unzip/232b0826-d65c-4c92-bde7-64832286df9e/ Bd291518-ffe1-45de-8ddc-4994486b6e16.1519/index_files/b7dfd804-377b-43ac-b914-502d8e113f4e.png "style=" border:0 px; "alt=" B7dfd804-377b-43ac-b914-502d8e113f4e.png "/>
Step Two:
650) this.width=650; "Src=" https://note.wiz.cn/unzip/232b0826-d65c-4c92-bde7-64832286df9e/ Bd291518-ffe1-45de-8ddc-4994486b6e16.1519/index_files/a80f433f-e484-4cb2-85e3-832e6425837a.png "style=" border:0 px; "alt=" A80f433f-e484-4cb2-85e3-832e6425837a.png "/>
Step three: Implement the function of JNI acquisition device (hw_device_t) Operation
650) this.width=650; "Src=" https://note.wiz.cn/unzip/232b0826-d65c-4c92-bde7-64832286df9e/ Bd291518-ffe1-45de-8ddc-4994486b6e16.1519/index_files/d1adfde3-2cde-4e63-bbcf-798bf5addfea.png "style=" border:0 px; "alt=" D1adfde3-2cde-4e63-bbcf-798bf5addfea.png "/>
Iv. functions that implement the release (free) device (hw_device_t) of the JNI invocation , contrary to the third step intent
650) this.width=650; "Src=" https://note.wiz.cn/unzip/232b0826-d65c-4c92-bde7-64832286df9e/ Bd291518-ffe1-45de-8ddc-4994486b6e16.1519/index_files/3f6f0f48-110f-45c8-8f7c-9805735bdf9b.png "style=" border:0 px; "alt=" 3f6f0f48-110f-45c8-8f7c-9805735bdf9b.png "/>
650) this.width=650; "Src=" https://note.wiz.cn/unzip/232b0826-d65c-4c92-bde7-64832286df9e/ Bd291518-ffe1-45de-8ddc-4994486b6e16.1519/index_files/805503d4-95ca-4179-844f-a34536cfa414.png "style=" border:0 px; "alt=" 805503d4-95ca-4179-844f-a34536cfa414.png "/>
650) this.width=650; "Src=" https://note.wiz.cn/unzip/232b0826-d65c-4c92-bde7-64832286df9e/ Bd291518-ffe1-45de-8ddc-4994486b6e16.1519/index_files/a9661b87-f2be-401d-bfde-5d6267e6b3c0.jpg "style=" border:0 px; "alt=" a9661b87-f2be-401d-bfde-5d6267e6b3c0.jpg "/>
Full code
Hal_led.h
#ifndef __hal_led_h__ #define __HAL_LED_H__ #include
Hal_led.c
#define LOG_TAG "Myled_hal" #include <stdlib.h> #include "Hal_led.h" #include Android.mk
Local_path:= $ (call My-dir) include $ (clear_vars) Local_module_path: = $ (target_out_shared_libraries)/hwlocal_module_ TAGS: = optionallocal_module:= myled_hal.defaultlocal_src_files:= hal_led.clocal_shared_libraries: = libutilsinclu De $ (build_shared_library)
This article is from the "lilin9105" blog, make sure to keep this source http://7071976.blog.51cto.com/7061976/1426717