1# Charging Current and Voltage Limit Customization 2 3## Overview 4 5### Introduction 6 7By default, OpenHarmony supports setting of charging current and voltage limits. When a device is being charged, the battery temperature may become excessively high due to the impact of ambient environment. In such a case, the charging current or voltage needs to be limited to ensure safety use of the device. However, the impact of charging current or voltage on device safety varies according to product specifications. To address this issue, OpenHarmony provides the function of customizing charging current and voltage limits. 8 9### Constraints 10 11 12The configuration path for battery level customization is subject to the [configuration policy](https://gitee.com/openharmony/customization_config_policy). In this development guide, `/vendor` is used as an example of the configuration path. During actual development, you need to modify the customization path based on the product configuration policy. 13 14## How to Develop 15 16### Setting Up the Environment 17 18**Hardware requirements:** 19 20Development board running the standard system, for example, the DAYU200 or Hi3516D V300 open source suite. 21 22**Environment requirements:** 23 24For details about the requirements on the Linux environment, see [Quick Start](../quick-start/quickstart-overview.md). 25 26### Getting Started with Development 27 28The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568) as an example to illustrate charging current and voltage limit configuration. 29 301. Create the `battery` folder in the product directory [/vendor/hihope/rk3568](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568). 31 322. Create a target folder by referring to the [default folder of charging current and voltage limit configuration](https://gitee.com/openharmony/powermgr_battery_manager/tree/master/services/native/profile), and install it in `//vendor/hihope/rk3568/battery`. The content is as follows: 33 34 ```text 35 profile 36 ├── BUILD.gn 37 ├── battery_config.json 38 ``` 39 403. Write the custom `battery_config.json` file by referring to the [battery_config.json](https://gitee.com/openharmony/powermgr_battery_manager/blob/master/services/native/profile/battery_config.json) file in the default folder of charging current and voltage limit configuration. For example: 41 42 ```json 43 { 44 "charger": { 45 "current_limit":{ 46 "path": "/data/service/el0/battery/current_limit" 47 }, 48 "voltage_limit":{ 49 "path": "/data/service/el0/battery/voltage_limit" 50 } 51 } 52 } 53 ``` 54 554. Write the `BUILD.gn` file by referring to the [BUILD.gn](https://gitee.com/openharmony/powermgr_battery_manager/blob/master/services/native/profile/BUILD.gn) in the default folder of charging current and voltage limit configuration to pack the `battery_config.json` file to the `//vendor/etc/battery` directory. The configuration is as follows: 56 57 ```shell 58 import("//build/ohos.gni") # Reference build/ohos.gni. 59 60 ohos_prebuilt_etc("battery_config") { 61 source = "battery_config.json" 62 relative_install_dir = "battery" 63 install_images = [ chipset_base_dir ] # Required configuration for installing the battery_config.json file in the vendor directory. 64 part_name = "product_rk3568" # Set part_name to product_rk3568 for subsequent build. 65 } 66 ``` 67 685. Add the build target to `module_list` in [ohos.build](https://gitee.com/openharmony/vendor_hihope/blob/master/rk3568/ohos.build) in the `/vendor/hihope/rk3568` directory. For example: 69 70 ```json 71 { 72 "parts": { 73 "product_rk3568": { 74 "module_list": [ 75 "//vendor/hihope/rk3568/default_app_config:default_app_config", 76 "//vendor/hihope/rk3568/image_conf:custom_image_conf", 77 "//vendor/hihope/rk3568/preinstall-config:preinstall-config", 78 "//vendor/hihope/rk3568/resourceschedule:resourceschedule", 79 "//vendor/hihope/rk3568/etc:product_etc_conf", 80 "//vendor/hihope/rk3568/battery/profile:battery_config" # Add the configuration for building of battery_config. 81 ] 82 } 83 }, 84 "subsystem": "product_hihope" 85 } 86 ``` 87 In the preceding code, `//vendor/hihope/rk3568/battery/` is the folder path, `profile` is the folder name, and `battery_config` is the build target. 88 896. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md). 90 91 ```shell 92 ./build.sh --product-name rk3568 --ccache 93 ``` 94 957. Burn the customized version to the DAYU200 development board. 96 97### Debugging and Verification 98 991. Build the battery-specific hats test cases. For details about the build commands and framework setup, see [XTS Subsystem](https://gitee.com/openharmony/xts_hats). 100 1012. Run the test cases, and check the test report. 102 103  104 105## Reference 106 107During development, you can refer to the [default charging current and voltage configuration](https://gitee.com/openharmony/powermgr_battery_manager/blob/master/services/native/profile/battery_config.json), as shown below: 108 109 110 111```json 112{ 113 "charger": { 114 "current_limit":{ 115 "path": "/data/service/el0/battery/current_limit" 116 }, 117 "voltage_limit":{ 118 "path": "/data/service/el0/battery/voltage_limit" 119 } 120 } 121} 122``` 123 124Packing path: /system/etc/battery 125