高通在N版本之前一直有一個可以操作GPIO口的工具,實際也是操作對應的寄存器。但是N之後沒有默認添加到代碼中。該工具即爲大家所熟知的/system/bin/r。
現在以O版本爲例,添加該工具。
一、添加方式
1、首先需要獲取r.c工具,我們可以從N版本上獲取。目錄爲:system/core/toolbox/r.c
2、然後需要添加編譯代碼,在編譯時將r.c編譯到系統中,添加路徑爲:system/core/toolbox/Android.mk
include $(CLEAR_VARS)
LOCAL_SRC_FILES := r.c
LOCAL_CFLAGS += $(common_cflags)
LOCAL_MODULE := r
LOCAL_MODULE_TAGS := debug
include $(BUILD_EXECUTABLE)
3、添加完成後我們編譯system.img刷到機器裏就可以使用了。
二、/system/bin/r使用方法
1、以GPIO49爲例,十進制49對應的16進製爲2E,每個GPIO均有這3個寄存器描述功能,包括輸入輸出,驅動電流,是否上拉或者下拉,中斷功能。
所以三個寄存器對應的地址爲:
0x01000000+0x1000*2Eh = 0x0102E000
0x01000004+0x1000*2Eh = 0x0102E004
0x01000008+0x1000*2Eh = 0x0102E008
讀取方法:
adb root
adb shell
/system/bin/r 0x0102E000 --》0102E000: 00000201
/system/bin/r 0x0102E004 --》0102E004: 00000003
/system/bin/r 0x0102E008 --》0102E008: 000000e2
對於讀出來數據的定義通過寄存器對每位數據的定義可以得出:
201h '1000000001 9bit=1 代表輸出;6-8bit=0,驅動能力2mA;2-5位0,普通GPIO功能;0-1位=1,下拉功能。
3h'0011 代表輸出爲高。
E2h'11100010 最低位爲0,代表disable中斷功能。
2、我們分別看下三個寄存器分別代表什麼意思
0x01000000+ 0x1000*n TLMM_GPIO_CFGn, n=[0..121]
Type: RW
Clock: GCC_TLMM_AHB_CLK
Reset State: 0x00000001
The GPIO_CFG[n] controls the GPIO Output Enable, Drive strength, Pull and Alternate Function for GPIO[n]. The default PULL can vary for different GPIOs and can be found in the pinout spreadsheet. The default drive setting for all GPIOs is '000' (2 mA).
0x01000004+ 0x1000*n TLMM_GPIO_IN_OUTn, n=[0..121]
Type: RW
Clock: GCC_TLMM_AHB_CLK
Reset State: 0x00000000
The GPIO_IN_OUT[n] controls the Out and In on the GPIO[n]. The GPIO_IN bit is read-only.
Bits | name | Type | Description |
0 | GPIO_OUT | RW | Controls the value of the GPIO Output |
1 | GPIO_IN | R | Allows you to read the Input value of the GPIO |
0x01000008+ 0x1000*n TLMM_GPIO_INTR_CFGn, n=[0..121]
Type: RW
Clock: GCC_TLMM_AHB_CLK
Reset State: 0x000000E2
工具:https://download.csdn.net/download/u010787514/10643145