1. Framework
APP (Java language Implementation)
-------------------------------
JNI (c + + language implementation) provides an interface for Java to perform C functions down-access HAL
-------------------------------
HAL (c or C + + language implementation) encapsulates hardware operation details
-------------------------------
Driver (C language Implementation) operating hardware
If JNI is written by itself, then its interface only knows that the application can only write itself, so it must use the existing JNI of Android, but Hal and the driver can write their own, as long as the HAL can meet the requirements of JNI, then the application can be written by other people to access the driver through Universal JNI.
2. Android Lighting System Frame
App: Battery light app, notification light app, backlight app
---------------------
JNI:com_android_server_lights_LightsService.cpp
---------------------
HAL: Write Yourself: HAL_LIGHTS.C
---------------------
Drive: Write yourself: leds_4412.c
How to write:
(1): See function
Battery lights and notification lights: On the hardware is the same, color, flashing
Backlight: Adjust LCD brightness
(2): Write driver
Battery lamp and notification light: Three LEDs (red, green and blue respectively) together, drive operator 3 LEDs
Backlight: Control the duty ratio of the output PWM
(3): Write Hal
Dividing the hardware LEDs into different logic lights
JNI Requirements Analysis:
(1) Obtaining hw_modult_t structure
(2) Call Get_device, call Module->methods->open according to different name, get different light_device_t struct
See the source of JNI, you can see a lot of name, we wrote the HAL will only implement "light_id_backlight (backlight)", "Light_id_battery", "Light_id_notifications"
HAL provides analysis:
(1) Realizing hw_module_t
(2) Implement the Open function, according to different name return different light_device_t structure, which has hw_device_t structure and set_light function, so for different lights need to implement different set_light functions, in set_ Action Driver inside light function
Drive Analysis:
(1) operation of Red Green and blue three LEDs, to achieve light, off, flashing three functions;
(2) for backlight, set the PWM duty ratio
8.1 Android Lighting System _ Overall Framework