[RK3288][Android6.0] 调试笔记 --- 通用GPIO驱动控制LED【转】

本文转载自:http://m.blog.csdn.net/kris_fei/article/details/69553422

Platform: ROCKCHIP
OS: Android 6.0
Kernel: 3.10.92

由于板子没有lcd无法得知sd卡升级是否完成,因此使用LED显示.
Recovery中升级完成后控制GPIO输出高电平点亮LED.

系统自带GPIO控制驱动:
内核已经自带了通用GPIO驱动,可以直接在用户空间操作.
路径: /sys/class/gpio
root@rk3288:/sys/class/gpio # ls
export
gpiochip0
gpiochip120
gpiochip152
gpiochip184
gpiochip216
gpiochip24
gpiochip248
gpiochip280
gpiochip56
gpiochip88
unexport

比如我要操作GPIO8_A6作为高电平输出有效, 那么有以下问题:
1. 对应的gpio number是多少呢?
2. 如何设置成输出
3. 如何输出高电平

问题1:
可以通过/sys/kernel/debug/gpio查询信息:
root@rk3288:/sys/kernel/debug # cat gpio                                       
//snip
GPIOs 184-215, platform/ff770000.pinctrl, gpio6:
 gpio-193 (?                   ) in  hi
 gpio-194 (?                   ) in  hi

GPIOs 216-247, platform/ff770000.pinctrl, gpio7:
 gpio-218 (enable              ) out hi
 gpio-219 (lcd_en              ) in  hi
 gpio-220 (lcd_cs              ) in  hi
 gpio-221 (gslX680 wake pin    ) out hi
 gpio-222 (gslX680 irq pin     ) out lo
 gpio-223 (headset_gpio        ) in  hi
 gpio-233 (?                   ) in  hi
 gpio-234 (?                   ) in  hi

GPIOs 248-279, platform/ff770000.pinctrl, gpio8:

GPIOs 280-311, platform/ff770000.pinctrl, gpio15:

可以看到gpio8是以nubmer为248开始, 那么GPIO8_A6就是 248 + 6 = 254
接下来就可以导出gpio了
root@rk3288:/sys/class/gpio # echo 254 > export                          
root@rk3288:/sys/class/gpio # ls
export
gpio254
......

问题2
root@rk3288:/sys/class/gpio/gpio254 # echo out > direction                     
root@rk3288:/sys/class/gpio/gpio254 # cat direction                            
out

问题3:
root@rk3288:/sys/class/gpio/gpio254 # echo 1 > value                           
root@rk3288:/sys/class/gpio/gpio254 # cat value                                
1

解决方法:
init.rc
[kris@:~/rk3288/device/rockchip/common/recovery/etc]$ g df
diff --git a/recovery/etc/init.rc b/recovery/etc/init.rc
index efe2a5d..75d7554 100755
--- a/recovery/etc/init.rc
+++ b/recovery/etc/init.rc
@@ -85,6 +85,12 @@ on late-init
 on property:sys.powerctl=*
    powerctl ${sys.powerctl}
 
+#Kris, 170407, GPIO8_A6 -> gpio254, used to inform sd upgrade complete.
+on property:sdupgrade.complete=true
+       write /sys/class/gpio/export 254
+       write /sys/class/gpio/gpio254/direction out
+       write /sys/class/gpio/gpio254/value 1
+
 service ueventd /sbin/ueventd
     critical
     seclabel u:r:ueventd:s0

recovery.cpp
[kris@:~/rk3288/bootable/recovery]$ g df
diff --git a/recovery.cpp b/recovery.cpp
index 8299672..a0edc15 100755
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -2285,6 +2285,10 @@ HANDLE_STATUS :
         strcat(kernellogPath, "/kernel.txt");
         save_kernel_log(kernellogPath);
         #endif
+
+       //Kris, 170407, light led on after sd upgrade complete.
+       property_set("sdupgrade.complete", "true");
+
                if (bSDMounted)
             checkSDRemoved();

参考:
http://blog.csdn.net/cjsycyl/article/details/46310939

上一篇:怎么用snapman一个人在三天内开发出一个复杂的软件开发项目管理系统


下一篇:关于静态注册BroadcastReceiver接收不到广播的问题