static int board_probe_bat_status(int standby_mode) { int bat_cal = 1; int ret, chargemode = 0; //当前可以确定是火牛开机,但是是否开机还不确定,需要确认电池是否存在 //当电池不存在即开机,电池存在则关机 //新添加,根据环境变量,是启动当前的待机,或者android待机功能 ret = script_parser_fetch("charging_type", "charging_type", &chargemode, 1); if((!ret) && chargemode) { gd->chargemode = 1; return 0; } if(battery_charge_cartoon_init(0) < 0) { tick_printf("init charge cartoon fail\n"); return -1; } bat_cal = axp_probe_rest_battery_capacity(); printf("bat not inited\n"); if(battery_charge_cartoon_init(bat_cal/(100/(SUNXI_BAT_BMP_MAX-1))) < 0) { tick_printf("init charge cartoon fail\n"); return -1; } if((!bat_cal) && (standby_mode)) { bat_cal = 100; } return bat_cal; }
static int board_standby_status(int source_bat_cal) { int bat_cal, this_bat_cal; int i, j, status; int one_delay; int ret; boot_standby_action = 0; this_bat_cal = source_bat_cal; tick_printf("base bat_cal = %d\n", this_bat_cal); if(this_bat_cal > 95) { this_bat_cal = 100; } //启动中断检测 usb_detect_for_charge(BOOT_USB_DETECT_DELAY_TIME + 200); //启动axp检测 power_limit_detect_enter(); status = 1; goto __start_case_status__; /****************************************************************** * * standby 返回值说明 * * -1: 进入standby失败 * 1: 普通按键唤醒 * 2: 电源按键短按唤醒 * 3: 电源按键长按唤醒 * 4: 外部电源移除唤醒 * 5: 电池充电完成 * 6: 在唤醒状态下外部电源被移除 * 7: 在唤醒状态下充电完成 * ******************************************************************/ do { tick_printf("enter standby\n"); board_display_layer_close(); power_limit_detect_exit(); status = board_try_boot_standby(); tick_printf("exit standby by %d\n", status); bat_cal = axp_probe_rest_battery_capacity(); tick_printf("current bat_cal = %d\n", bat_cal); if(bat_cal > this_bat_cal) { this_bat_cal = bat_cal; } __start_case_status__: tick_printf("status = %d\n", status); switch(status) { case 2: //短按power按键导致唤醒 //启动中断检测 boot_standby_action = 0; power_limit_detect_enter(); board_display_layer_open(); case 1: //重新计算动画延时时间 if(this_bat_cal == 100) { one_delay = 1000; } else { one_delay = 1000/(10 - (this_bat_cal/10)); } //绘制动画 for(j=0;j<3;j++) { for(i=this_bat_cal/(100/(SUNXI_BAT_BMP_MAX-1));i<SUNXI_BAT_BMP_MAX;i++) { battery_charge_cartoon_rate(i); if(boot_standby_action & 0x08) //存在外部电源 { boot_standby_action &= ~0x08; j = 0; } else if(boot_standby_action & 0x02) //短按 { boot_standby_action &= ~2; j = 0; } else if(boot_standby_action & 0x01) //长按 { battery_charge_cartoon_exit(); power_limit_detect_exit(); return 0; } else if(boot_standby_action & 0x10) //拔掉外部电源,没有外部电源 { status = 10; boot_standby_action &= ~0x10; goto __start_case_status__; } __msdelay(one_delay); } } //停止动画,固定显示当前电量 battery_charge_cartoon_rate(this_bat_cal/(100/(SUNXI_BAT_BMP_MAX-1))); for(j=0;j<4;j++) { if(boot_standby_action & 0x08) //存在外部电源 { boot_standby_action &= ~0x08; j = 0; } else if(boot_standby_action & 0x10) //拔掉外部电源,没有外部电源 { status = 10; boot_standby_action &= ~0x10; goto __start_case_status__; } else if(boot_standby_action & 0x01) //长按 { battery_charge_cartoon_exit(); power_limit_detect_exit(); return 0; } __msdelay(250); } break; case 3: //长按电源按键之后,关闭电池图标,进入系统 battery_charge_cartoon_exit(); return 0; case 4: //当移除外部电源时候,重新显示当前电池图标后,3秒后关机 case 5: //当电池充电完成的时候,需要关机 //启动中断检测 boot_standby_action = 0; power_limit_detect_enter(); board_display_layer_open(); battery_charge_cartoon_rate(this_bat_cal/(100/(SUNXI_BAT_BMP_MAX-1))); case 6: case 7: if((status != 4) && (status != 5)) { board_display_layer_open(); battery_charge_cartoon_rate(this_bat_cal/(100/(SUNXI_BAT_BMP_MAX-1))); } case 10: battery_charge_cartoon_rate(this_bat_cal/(100/(SUNXI_BAT_BMP_MAX-1))); __msdelay(500); do { if(!(boot_standby_action & 0x04)) { ret = battery_charge_cartoon_degrade(5); } else { status = 1; battery_charge_cartoon_reset(); goto __start_case_status__; } } while(!ret); battery_charge_cartoon_exit(); power_limit_detect_exit(); return -1; case 8: //standby过程中检测到vbus存在变化 { usb_detect_for_charge(BOOT_USB_DETECT_DELAY_TIME + 200); } break; case 9: //standby过程中检测到vbus移除,同时存在普通dc { // power_set_usbpc(); } break; default: break; } } while(1); }
static int board_probe_bat_status(int standby_mode) { int dc_exist, bat_exist, counter; int bat_init = 0; int bat_cal = 1; int ret, chargemode = 0; //当前可以确定是火牛开机,但是是否开机还不确定,需要确认电池是否存在 //当电池不存在即开机,电池存在则关机 //新添加,根据环境变量,是启动当前的待机,或者android待机功能 ret = script_parser_fetch("charging_type", "charging_type", &chargemode, 1); if((!ret) && chargemode) { chargemode = 1; } counter = 4; do { dc_exist = 0; bat_exist = 0; axp_power_get_dcin_battery_exist(&dc_exist, &bat_exist); printf("bat_exist=%d\n", bat_exist); if(bat_exist == -1) { printf("bat is unknown\n"); if(!chargemode) { if(!bat_init) { if(battery_charge_cartoon_init(0) < 0) { tick_printf("init charge cartoon fail\n"); return -1; } bat_init = 1; } } __msdelay(500); } else { break; } } while(counter --); #ifdef FORCE_BOOT_STANDBY bat_exist = 1; #else if(standby_mode) { bat_exist = 1; } #endif if(bat_exist <= 0) { tick_printf("no battery exist\n"); if(chargemode) { return 0; } if(bat_init) { battery_charge_cartoon_exit(); } return 0; } if(chargemode) { printf("use android charge mode"); gd->chargemode = 1; return 0; } if(!bat_init) { bat_cal = axp_probe_rest_battery_capacity(); printf("bat not inited\n"); if(battery_charge_cartoon_init(bat_cal/(100/(SUNXI_BAT_BMP_MAX-1))) < 0) { tick_printf("init charge cartoon fail\n"); return -1; } } if((!bat_cal) && (standby_mode)) { bat_cal = 100; } return bat_cal; }