当前位置:   article > 正文

嵌入式系统移植 - uBoot : 添加关机充电(cmd_charge.c)动画_uboot关机充电管理

uboot关机充电管理

添加关机充电动画

说明

该补丁需要修改 cmd_charge.c 文件的代码, 该文件位置在 uboot 文件夹下,

修改源码

diff --git a/include/configs/rk30plat.h b/include/configs/rk30plat.h
index 3a25fc7..d768832 100755
--- a/include/configs/rk30plat.h
+++ b/include/configs/rk30plat.h
@@ -215,7 +215,8 @@
 #define CONFIG_RK32_DSI
 #endif /* CONFIG_RKCHIP_RK3126 */
 
-#undef CONFIG_UBOOT_CHARGE
+/* #undef CONFIG_UBOOT_CHARGE  */
+#define CONFIG_UBOOT_CHARGE
 
 #else
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
diff --git a/common/cmd_charge.c b/common/cmd_charge.c
index f9ce5bd..6fb7980 100755
--- a/common/cmd_charge.c
+++ b/common/cmd_charge.c
@@ -22,7 +22,7 @@
 #include <resource.h>
 #include <asm/arch/rkplat.h>
 
-/*#define DEBUG*/
+//#define DEBUG
 #define LOGE(fmt, args...) printf(fmt "\n", ##args)
 #ifdef DEBUG
 #define LOGD(fmt, args...) printf(fmt "\n", ##args)
@@ -50,6 +50,7 @@
 #define NOT_EXIT             		0
 #define EXIT_BOOT           		1
 #define EXIT_SHUTDOWN            	2
+#define EXIT_WITHOUT_BAT            3
 
 #define DEF_CHARGE_DESC_PATH		"charge_anim_desc.txt"
 #define DEFAULT_ANIM_DELAY			80000 //us
@@ -78,6 +79,11 @@ u8 g_increment = 0;
 
 int timer_interrupt_wakeup = 0;
 
+static inline unsigned int diff_fix_duration(unsigned int base) {
+	unsigned int max = 0xFFFFFFFF / 24000;
+	return max - base;
+}
+
 //return duration(ms).
 static inline unsigned int get_fix_duration(unsigned int base) {
 	unsigned int max = 0xFFFFFFFF / 24000;
@@ -149,7 +155,7 @@ int power_key_pressed(void) {
 		if (power_pressed) {
 			//still pressing
 #define LONG_PRESSED_TIME 2000 //2s
-			if (get_fix_duration(power_pressed_time) >= LONG_PRESSED_TIME) {
+			if (diff_fix_duration(get_fix_duration(power_pressed_time)) >= LONG_PRESSED_TIME) {
 				//long pressed.
 				power_pressed_state = KEY_LONG_PRESSED;
 			}
@@ -216,23 +222,25 @@ int check_charging(void) {
 	get_power_bat_status(&batt_status);
 
 	// if no exist bat but charging 
-	if((batt_status.state_of_chrg)&&(!batt_status.isexistbat))
-	{
-		printf("charging but no exist batterry!.");
-		return EXIT_BOOT;
+	/* Modity Tower 20180127 */
+	if((batt_status.state_of_chrg) && (!batt_status.isexistbat)) {
+		printf("ERROR: charging but no exist batterry!. \n");
+		return EXIT_WITHOUT_BAT;
+		//return EXIT_BOOT;
 	}
-	
-	if(!batt_status.state_of_chrg)
-	{
-		printf("pmic not charging.");
+
+	if(!batt_status.state_of_chrg) {
+		printf("INFO: pmic not charging. \n");
 		pmic_charger_setting(0);
 		return EXIT_SHUTDOWN;
 	}
+	
 	/*
-	   if (check cap enough)
-	   return EXIT_BOOT;
-	   */
-	return 0;
+	if (check cap enough)
+		return EXIT_BOOT;
+	*/
+	
+	return NOT_EXIT;
 }
 
 /**
@@ -265,11 +273,13 @@ static anim_level_conf* level_confs = NULL;
 static int level_conf_num = 0;
 static int only_current_level = false;
 static char bat_err_path[MAX_INDEX_ENTRY_PATH_LEN];
+static char bat_without_path[MAX_INDEX_ENTRY_PATH_LEN];
 
 #define OPT_CHARGE_ANIM_DELAY       "delay="
 #define OPT_CHARGE_ANIM_LOOP_CUR    "only_current_level="
 #define OPT_CHARGE_ANIM_LEVELS      "levels="
 #define OPT_CHARGE_ANIM_BAT_ERROR   "bat_error="
+#define OPT_CHARGE_ANIM_BAT_WITHOUT "bat_without="
 #define OPT_CHARGE_ANIM_LEVEL_CONF  "min_level="
 #define OPT_CHARGE_ANIM_LEVEL_NUM   "num="
 #define OPT_CHARGE_ANIM_LEVEL_PFX   "prefix="
@@ -421,6 +431,12 @@ static bool load_anim_desc(const char* desc_path, bool dump) {
 			snprintf(bat_err_path, sizeof(bat_err_path), "%s",
 					arg + strlen(OPT_CHARGE_ANIM_BAT_ERROR));
 			LOGD("Found battery error image:%s", bat_err_path);
+			
+		} else if (!memcmp(arg, OPT_CHARGE_ANIM_BAT_WITHOUT,
+					strlen(OPT_CHARGE_ANIM_BAT_WITHOUT))) {
+			snprintf(bat_without_path, sizeof(bat_without_path), "%s",
+					arg + strlen(OPT_CHARGE_ANIM_BAT_WITHOUT));
+			LOGD("Found battery without image:%s", bat_without_path);
 		} else {
 			LOGE("Unknown arg:%s", arg);
 			continue;
@@ -702,13 +718,14 @@ int do_charge(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		#endif
 		//step 2: handle timeouts.
 		if (IS_BRIGHT(g_state.brightness)) {
-			unsigned int idle_time = get_fix_duration(g_state.screen_on_time);
+			unsigned int idle_time = diff_fix_duration(get_fix_duration(g_state.screen_on_time));
 			//printf("idle_time:%ld\n", idle_time);
+#if 1
 			if (idle_time > SCREEN_OFF_TIMEOUT) {
 				LOGD("screen off");
 				brightness = SCREEN_OFF;
 			}
-	#if 0
+#else
 			if (idle_time > SCREEN_OFF_TIMEOUT) {
 				LOGD("screen off");
 				brightness = SCREEN_OFF;
@@ -716,7 +733,7 @@ int do_charge(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 				LOGD("screen dim");
 				brightness = SCREEN_DIM;
 			}
-	#endif
+#endif
 		}
 
 		//step 3: check power key pressed state.
@@ -761,7 +778,7 @@ int do_charge(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 #ifdef CONFIG_CHARGE_TIMER_WAKEUP
 			timer1_irq_deinit();
 #endif
-			//close some ldo
+			//on some ldo
   			power_on_pmic();
 			
 			mdelay(10);
@@ -774,7 +791,7 @@ int do_charge(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		//step 5:step anim when screen is on.
 		if (IS_BRIGHT(brightness)) {
 			//do anim when screen is on.
-			unsigned int duration = get_fix_duration(anim_time) * 1000;
+			unsigned int duration = diff_fix_duration(get_fix_duration(anim_time));
 			if (!IS_BRIGHT(g_state.brightness)
 					|| duration >= get_delay(&g_state)) {
 				anim_time = get_timer(0);
@@ -788,9 +805,19 @@ int do_charge(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		//udelay(100);// 50ms.
 	}
 exit:
+    /* If there is no battery */
+	if (exit_type == EXIT_WITHOUT_BAT) {
+		set_brightness(SCREEN_BRIGHT, &g_state);
+		//TODO:show warning logo.
+		show_resource_image("images/battery_without.bmp");
+		udelay(3000000); //3 sec.
+		exit_type = EXIT_BOOT;
+	}
+	
 	/* disable fb buffer flip */
 	lcd_enable_flip(false);
 	set_brightness(SCREEN_OFF, &g_state);
+	
 	if (exit_type == EXIT_BOOT) {
 		#ifdef CONFIG_POWER_FG_ADC
 		if(fg_adc_storage_flag_load()==0)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
diff --git a/drivers/power/fuel_gauge/fg_rk816.c b/drivers/power/fuel_gauge/fg_rk816.c
index eaa8da2..270c1c9 100755
--- a/drivers/power/fuel_gauge/fg_rk816.c
+++ b/drivers/power/fuel_gauge/fg_rk816.c
@@ -1317,8 +1317,10 @@ static int rk816_bat_update(struct pmic *p, struct pmic *bat)
 	}
 
 	battery->state_of_chrg = rk816_fg.di.state_of_chrg;
-	battery->isexistbat = 1;
-
+	// Modify Tower 20191112
+	//battery->isexistbat = 1;
+	battery->isexistbat = !rk816_fg.di.virtual_power;
+	
 	return 0;
 }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
diff --git a/tools/resource_tool/resources/charge_anim_desc.txt b/tools/resource_tool/resources/charge_anim_desc.txt
old mode 100644
new mode 100755
index 40faf88..cf2d07d
--- a/tools/resource_tool/resources/charge_anim_desc.txt
+++ b/tools/resource_tool/resources/charge_anim_desc.txt
@@ -1,5 +1,5 @@
 #default anim delay.
-delay=900
+delay=1
 
 #only show current level's pics.
 only_current_level=false
@@ -7,6 +7,9 @@ only_current_level=false
 #reserve.
 bat_error=images/battery_fail.bmp
 
+#without battery
+bat_without=images/battery_fail.bmp
+
 #num of level configs.
 levels=6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
diff --git a/tools/resource_tool/resources/images/battery_without.bmp b/tools/resource_tool/resources/images/battery_without.bmp
new file mode 100755
index 0000000..2ec45b3
Binary files /dev/null and b/tools/resource_tool/resources/images/battery_without.bmp differ
  • 1
  • 2
  • 3
  • 4
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/272090
推荐阅读
相关标签
  

闽ICP备14008679号