[全志平台Android11]在恢复出厂(recovery)时操作GPIO

本文介绍了如何在Android开发中通过调整sys.bl.config和GPIO来控制恢复出厂设置时的背光状态,满足特定需求,如防止白屏和亮灯。开发人员需耐心解决问题并处理各种奇奇怪怪的需求。
摘要由CSDN通过智能技术生成

一、前言

在我们开发时可能会遇到恢复出厂设置成功时会出现部分白屏,为了不让这一部分出现,决定采用在recovery成功时关掉背光,不让白屏出现。也会有需求是完成恢复出厂设置时亮灯,也可以采取我所说的方法去操作。

二、核心代码路径

Android_sdk/bootable/recovery/recovery_main.cpp
Android_sdk/bootable/recovery/etc/init.rc

 在init.rc服务中我们可以创建一个GPIO的操作服务给recovery_main.cpp中会有恢复出厂的流程调用。init.rc添加如下(在加这个服务之前先在串口中操作一遍):

+on property:sys.bl.config=0
+   write /sys/class/gpio/export 37 //通过原理图和dts可以计算出gpio号
+   write /sys/class/gpio/gpio37/direction out
+   write /sys/class/gpio/gpio37/value 0

 recovery_main.cpp:

....... 
static constexpr struct option OPTIONS[] = {
    { "fastboot", no_argument, nullptr, 0 },
    { "locale", required_argument, nullptr, 0 },
    { "reason", required_argument, nullptr, 0 },
    { "show_text", no_argument, nullptr, 't' },
    { nullptr, 0, nullptr, 0 },
  };

  bool show_text = false;
  bool fastboot = false;
  std::string locale;
  std::string reason;

  + //add core code start
  + android::base::SetProperty("sys.bl.config", "0");		//在这里操作GPIO将背光关闭
  + //add core code end 

  // The code here is only interested in the options that signal the intent to start fastbootd or
  // recovery. Unrecognized options are likely meant for recovery, which will be processed later in
  // start_recovery(). Suppress the warnings for such -- even if some flags were indeed invalid, the
  // code in start_recovery() will capture and report them.
  opterr = 0;

  int arg;
  int option_index;
  while ((arg = getopt_long(args_to_parse.size() - 1, args_to_parse.data(), "", OPTIONS,
                            &option_index)) != -1) {
.......

三、总结

在开发中会遇到很多奇奇怪怪的需求,需要耐住性子慢慢找出问题的解决方法。

  • 11
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值