Android 8.1 關機充電動畫(一)模式選擇

      網友投稿 1301 2022-05-30

      system:Android 8.1

      platform:RK3326/PX30

      uboot

      kernel

      Android 8.1 關機充電動畫(一)模式選擇

      Android 8.1 關機充電動畫(二)Uboot模式

      Android 8.1 關機充電動畫(三)Android模式

      文章目錄

      前言

      配置

      代碼分析

      總結

      附錄

      前言

      關機充電的動畫可以在u-boot或者Android的charger模式工作,這是兩個相互獨立的部分,RK平臺上需要在設備樹進行配置。顧名思義u-boot下的charger模式,系統仍然運行在loader下,并未啟動內核。

      Android的charger模式下,在引導程序運行期間會傳遞參數給內核,則會啟動內核并加載內核模塊,同時安卓系統也不會啟動,系統最終只工作charger模式。這里簡單記錄一下,在uboot中都做了哪些工作,根據什么條件選擇工作的模式。

      配置

      設備樹要增加節點charge-animation,這個rk的文檔里有相應的說明,在配置下面設備樹的配置中,我已經加上了注釋,對照這個看就行,不過所有屬性只適用u-boot下的關機充電,而不適用用Android下的關機充電,這個具體會在后面加以說明。

      這里暫時把已經啟動內核之后再進入charger的模式稱作Android下的關機充電,可能有些不妥,但是先這樣區分吧

      具體的配置如下;

      rockchip,uboot-charge-on = <0>; ,rockchip,android-charge-on = <1>; 這兩個屬性用于選擇后續的程序會進入到哪一種模式工作,后面在代碼中會加以區分。

      charge-animation { compatible = "rockchip,uboot-charge"; rockchip,uboot-charge-on = <0>; // 是否在U-Boot進行充電 rockchip,android-charge-on = <1>; // 是否在Android進行充電 rockchip,uboot-exit-charge-level = <5>; // U-Boot充電時,允許開機的最低電量 rockchip,uboot-exit-charge-voltage = <3600>; // U-Boot充電時,允許開機的最低電壓 rockchip,screen-on-voltage = <3400>; // U-Boot充電時,允許點亮屏幕的最低電壓 rockchip,uboot-low-power-voltage = <3350>; // U-Boot無條件強制進入充電模式的最低電壓 rockchip,system-suspend = <0>; // 滅屏時進入trust進行低功耗待機 rockchip,auto-off-screen-interval = <10>;// 亮屏超時后自動滅屏,單位秒。(如果沒有這個屬性,則默認15s) rockchip,auto-wakeup-interval = <0>; // 休眠自動喚醒時間,單位秒。(如果值為0或沒有這個屬性,則禁止休眠自動喚醒) rockchip,auto-wakeup-screen-invert = <0>; // 休眠自動喚醒的時候,是否讓屏幕產生亮/滅效果 status = "okay"; };

      1

      2

      3

      4

      5

      6

      7

      8

      9

      10

      11

      12

      13

      14

      代碼分析

      可以定位到u-boot/drivers/power/charge_animation.c,目前只分析一下函數static int charge_animation_show(struct udevice *dev),具體代碼見最后的附錄

      這個函數會在啟動內核之前進行一個簡單的檢測;

      1. Extrem low power charge? 2. Preboot cmd? 3. Valid boot mode? 4. U-Boot charge enabled by dts config? 5. Screen off before charge? 6. Enter charge !

      1

      2

      3

      4

      5

      6

      分別是1 檢測低電量,2 檢測啟動命令,3 檢測啟動模式,4 檢測設備樹配置,這四項檢測如果不符合會直接return,然后無法成功進入6 Enter charge的狀態。具體的可以在代碼里面慢慢看,至于第五點,不太清楚了。這里先把第四點的部分相關的代碼摳出來,如下:

      /* charge mode */ pdata->uboot_charge = dev_read_u32_default(dev, "rockchip,uboot-charge-on", 0); pdata->android_charge = dev_read_u32_default(dev, "rockchip,android-charge-on", 0); /* Enter android charge, set property for kernel */ if (pdata->android_charge) { env_update("bootargs", "androidboot.mode=charger"); } /* Not enable U-Boot charge, exit */ if (!pdata->uboot_charge) { debug("exit charge, due to not enable uboot charge\n"); return 0; }

      1

      2

      3

      4

      5

      6

      7

      8

      9

      10

      11

      12

      13

      14

      15

      可以看到這里有兩種情況

      uboot_charge如果在設備樹里配置為開啟,則無法進入Android 關機充電模式了,然后最終程序會進入到while(1)不斷循環顯示充電動畫,檢測到相應事件動作之后才會退出充電進入系統,或者掉電關機;

      android_charge在設備樹中設置開啟,并且 uboot_charge設置為關閉的情況下,會設置內核的啟動參數env_update("bootargs", "androidboot.mode=charger"),之后uboot會啟動內核,并傳參數給內核,告訴他,要進入Android關機充電的模式。

      總結

      這里篇幅較短,主要分析了在u-boot下charge_animation_show的部分工作流程即如何選擇最終充電的模式,下面會簡單介紹uboot下關機充電和Android下關機充電的動畫定制。

      附錄

      代碼可能已經更新請參考u-boot/drivers/power/charge_animation.c

      static int charge_animation_show(struct udevice *dev) { struct charge_animation_pdata *pdata = dev_get_platdata(dev); struct charge_animation_priv *priv = dev_get_priv(dev); const struct charge_image *image = priv->image; struct udevice *pmic = priv->pmic; struct udevice *fg = priv->fg; const char *preboot = env_get("preboot"); int image_num = priv->image_num; bool ever_lowpower_screen_off = false; bool screen_on = true; ulong show_start = 0, charge_start = 0, debug_start = 0; ulong delta; ulong ms = 0, sec = 0; int start_idx = 0, show_idx = -1, old_show_idx = IMAGE_SHOW_RESET; int soc, voltage, current, key_state; int i, charging = 1, ret; int boot_mode; int first_poll_fg = 1; /* * Check sequence: * * 1. Extrem low power charge? * 2. Preboot cmd? * 3. Valid boot mode? * 4. U-Boot charge enabled by dts config? * 5. Screen off before charge? * 6. Enter charge ! * */ if (!fuel_gauge_bat_is_exist(fg)) { printf("Exit charge: battery is not exist\n"); return 0; } /* Extrem low power charge */ ret = charge_extrem_low_power(dev); if (ret < 0) { printf("extrem low power charge failed, ret=%d\n", ret); return ret; } /* If there is preboot command, exit */ if (preboot && !strstr(preboot, "dvfs")) { printf("Exit charge: due to preboot cmd '%s'\n", preboot); return 0; } /* Not valid charge mode, exit */ #ifdef CONFIG_RKIMG_BOOTLOADER boot_mode = rockchip_get_boot_mode(); if ((boot_mode != BOOT_MODE_CHARGING) && (boot_mode != BOOT_MODE_UNDEFINE)) { printf("Exit charge: due to boot mode\n"); return 0; } #endif /* Not charger online, exit */ charging = fuel_gauge_get_chrg_online(fg); if (charging <= 0) { printf("Exit charge: due to charger offline\n"); return 0; } /* Enter android charge, set property for kernel */ if (pdata->android_charge) { env_update("bootargs", "androidboot.mode=charger"); printf("Android charge mode\n"); } /* Not enable U-Boot charge, exit */ if (!pdata->uboot_charge) { printf("Exit charge: due to not enable uboot charge\n"); return 0; } voltage = fuel_gauge_get_voltage(fg); if (voltage < 0) { printf("get voltage failed: %d\n", voltage); return -EINVAL; } /* If low power, turn off screen */ if (voltage <= pdata->screen_on_voltage + 50) { screen_on = false; ever_lowpower_screen_off = true; charge_show_bmp(NULL); } /* Auto wakeup */ if (pdata->auto_wakeup_interval) { printf("Auto wakeup: %dS\n", pdata->auto_wakeup_interval); autowakeup_timer_init(dev, pdata->auto_wakeup_interval); } /* Give a message warning when CONFIG_IRQ is not enabled */ #ifdef CONFIG_IRQ printf("Enter U-Boot charging mode\n"); #else printf("Enter U-Boot charging mode(without IRQ)\n"); #endif charge_start = get_timer(0); delta = get_timer(0); /* Charging ! */ while (1) { /* * At the most time, fuel gauge is usually a i2c device, we * should avoid read/write all the time. We had better set * poll seconds to update fuel gauge info. */ if (!first_poll_fg && get_timer(delta) < FUEL_GAUGE_POLL_MS) goto show_images; delta = get_timer(0); debug("step1 (%d)... \n", screen_on); /* * Most fuel gauge is I2C interface, it shouldn't be interrupted * during tansfer. The power key event depends on interrupt, so * so we should disable local irq when update fuel gauge. */ local_irq_disable(); /* Step1: Is charging now ? */ charging = fuel_gauge_get_chrg_online(fg); if (charging <= 0) { printf("Not charging, online=%d. Shutdown...\n", charging); /* wait uart flush before shutdown */ mdelay(5); /* PMIC shutdown */ pmic_shutdown(pmic); printf("Cpu should never reach here, shutdown failed !\n"); continue; } debug("step2 (%d)... show_idx=%d\n", screen_on, show_idx); /* Step2: get soc and voltage */ soc = fuel_gauge_get_soc(fg); if (soc < 0 || soc > 100) { printf("get soc failed: %d\n", soc); continue; } voltage = fuel_gauge_get_voltage(fg); if (voltage < 0) { printf("get voltage failed: %d\n", voltage); continue; } current = fuel_gauge_get_current(fg); if (current == -ENOSYS) { printf("get current failed: %d\n", current); continue; } first_poll_fg = 0; local_irq_enable(); show_images: /* * Just for debug, otherwise there will be nothing output which * is not good to know what happen. */ if (!debug_start) debug_start = get_timer(0); if (get_timer(debug_start) > 20000) { debug_start = get_timer(0); printf("[%8ld]: soc=%d%%, vol=%dmv, c=%dma, online=%d, screen_on=%d\n", get_timer(0)/1000, soc, voltage, current, charging, screen_on); } /* * If ever lowpower screen off, force screen_on=false, which * means key event can't modify screen_on, only voltage higher * then threshold can update screen_on=true; */ if (ever_lowpower_screen_off) screen_on = false; /* * Auto turn on screen when voltage higher than Vol screen on. * 'ever_lowpower_screen_off' means enter while loop with * screen off. */ if ((ever_lowpower_screen_off) && (voltage > pdata->screen_on_voltage)) { ever_lowpower_screen_off = false; screen_on = true; show_idx = IMAGE_SHOW_RESET; } /* * IMAGE_SHOW_RESET means show_idx show be update by start_idx. * When short key pressed event trigged, we will set show_idx * as IMAGE_SHOW_RESET which updates images index from start_idx * that calculate by current soc. */ if (show_idx == IMAGE_SHOW_RESET) { for (i = 0; i < image_num - 2; i++) { /* Find out which image we start to show */ if ((soc >= image[i].soc) && (soc < image[i + 1].soc)) { start_idx = i; break; } if (soc >= 100) { start_idx = image_num - 2; break; } } debug("%s: show_idx=%d, screen_on=%d\n", __func__, show_idx, screen_on); /* Mark start index and start time */ show_idx = start_idx; show_start = get_timer(0); } debug("step3 (%d)... show_idx=%d\n", screen_on, show_idx); /* Step3: show images */ if (screen_on) { /* Don't call 'charge_show_bmp' unless image changed */ if (old_show_idx != show_idx) { old_show_idx = show_idx; debug("SHOW: %s\n", image[show_idx].name); charge_show_bmp(image[show_idx].name); } /* Re calculate timeout to off screen */ if (priv->auto_screen_off_timeout == 0) priv->auto_screen_off_timeout = get_timer(0); } else { priv->auto_screen_off_timeout = 0; system_suspend_enter(pdata); } mdelay(5); /* Every image shows period */ if (get_timer(show_start) > image[show_idx].period) { show_start = get_timer(0); /* Update to next image */ show_idx++; if (show_idx > (image_num - 2)) show_idx = IMAGE_SHOW_RESET; } debug("step4 (%d)... \n", screen_on); /* * Step4: check key event. * * Short key event: turn on/off screen; * Long key event: show logo and boot system or still charging. */ key_state = check_key_press(dev); if (key_state == KEY_PRESS_DOWN) { old_show_idx = IMAGE_SHOW_RESET; /* NULL means show nothing, ie. turn off screen */ if (screen_on) charge_show_bmp(NULL); /* * Clear current image index, and show image * from start_idx */ show_idx = IMAGE_SHOW_RESET; /* * We turn off screen by charge_show_bmp(NULL), so we * should tell while loop to stop show images any more. * * If screen_on=false, means this short key pressed * event turn on the screen and we need show images. * * If screen_on=true, means this short key pressed * event turn off the screen and we never show images. */ if (screen_on) screen_on = false; else screen_on = true; } else if (key_state == KEY_PRESS_LONG_DOWN) { /* Only long pressed while screen off needs screen_on true */ if (!screen_on) screen_on = true; /* Is able to boot now ? */ if (soc < pdata->exit_charge_level) { printf("soc=%d%%, threshold soc=%d%%\n", soc, pdata->exit_charge_level); printf("Low power, unable to boot, charging...\n"); show_idx = image_num - 1; continue; } if (voltage < pdata->exit_charge_voltage) { printf("voltage=%dmv, threshold voltage=%dmv\n", voltage, pdata->exit_charge_voltage); printf("Low power, unable to boot, charging...\n"); show_idx = image_num - 1; continue; } /* Success exit charging */ printf("Exit charge animation...\n"); charge_show_logo(); break; } else { /* Do nothing */ } debug("step5 (%d)... \n", screen_on); /* Step5: Exit by ctrl+c */ if (ctrlc()) { if (voltage >= pdata->screen_on_voltage) charge_show_logo(); printf("Exit charge, due to ctrl+c\n"); break; } } if (pdata->auto_wakeup_interval) autowakeup_timer_uninit(); ms = get_timer(charge_start); if (ms >= 1000) { sec = ms / 1000; ms = ms % 1000; } printf("charging time total: %lu.%lus, soc=%d%%, vol=%dmv\n", sec, ms, soc, voltage); return 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

      Android 8.1 關機充電動畫(一)模式選擇

      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

      172

      173

      174

      175

      176

      177

      178

      179

      180

      181

      182

      183

      184

      185

      186

      187

      188

      189

      190

      191

      192

      193

      194

      195

      196

      197

      198

      199

      200

      201

      202

      203

      204

      205

      206

      207

      208

      209

      210

      211

      212

      213

      214

      215

      216

      217

      218

      219

      220

      221

      222

      223

      224

      225

      226

      227

      228

      229

      230

      231

      232

      233

      234

      235

      236

      237

      238

      239

      240

      241

      242

      243

      244

      245

      246

      247

      248

      249

      250

      251

      252

      253

      254

      255

      256

      257

      258

      259

      260

      261

      262

      263

      264

      265

      266

      267

      268

      269

      270

      271

      272

      273

      274

      275

      276

      277

      278

      279

      280

      281

      282

      283

      284

      285

      286

      287

      288

      289

      290

      291

      292

      293

      294

      295

      296

      297

      298

      299

      300

      301

      302

      303

      304

      305

      306

      307

      308

      309

      310

      311

      312

      313

      314

      315

      316

      317

      318

      319

      320

      321

      322

      323

      324

      325

      326

      327

      328

      329

      330

      331

      332

      333

      334

      335

      336

      337

      338

      339

      340

      341

      342

      343

      344

      345

      346

      347

      348

      349

      350

      351

      352

      Android

      版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。

      上一篇:游戲開發中的物理之使用KinematicBody2D
      下一篇:基于華為云智能問答機器人的AI詩歌生成【我的華為云體驗之旅】
      相關文章
      亚洲一区二区三区91| 老司机亚洲精品影院| 亚洲最大无码中文字幕| 亚洲av永久无码精品三区在线4| 亚洲AV成人无码久久精品老人| 自拍偷自拍亚洲精品第1页| 亚洲成人国产精品| 亚洲精品专区在线观看| 国产亚洲精品第一综合| 国产精品自拍亚洲| 国产一区二区三区亚洲综合| 国产精品亚洲а∨无码播放麻豆| 精品亚洲成A人在线观看青青| 亚洲日本天堂在线| 亚洲熟伦熟女专区hd高清| 亚洲人成网站在线在线观看| 亚洲AV无码专区在线观看成人| 亚洲中文字幕久久久一区| 亚洲熟妇无码一区二区三区导航| 99亚偷拍自图区亚洲| 亚洲精品GV天堂无码男同| 国产精品亚洲色婷婷99久久精品| 全亚洲最新黄色特级网站| 亚洲精品无码成人片在线观看| 国产精品亚洲二区在线观看| 区三区激情福利综合中文字幕在线一区亚洲视频1 | 亚洲综合久久精品无码色欲| 亚洲欧美成人综合久久久| 亚洲Aⅴ无码一区二区二三区软件| 亚洲视频在线一区二区| 亚洲人成图片小说网站| 亚洲人成电影在线天堂| 亚洲国产品综合人成综合网站| 国产日本亚洲一区二区三区| 亚洲av色香蕉一区二区三区蜜桃| 亚洲Av无码乱码在线znlu| 亚洲精品无码午夜福利中文字幕 | 亚洲成a人片77777老司机| 中文字幕亚洲精品| 中文字幕无码亚洲欧洲日韩| 亚洲av成人片在线观看|