GPIO操作的2种方法,1种查看状态的方法
关于GPIO寄存器的描述可以到展讯官网上下载GPIO寄存器的文档,由于网络差,当前登陆不进
1.GPIO被分为8组,每组GPIO对应的操作寄存器地址为 第一个地址即(0x40280000;0x40280080;0x40280100等等)
Gpio0 0x4028_0000 ~0x4028_007F
Gpio1 0x4028_0080 ~0x4028_00FF
Gpio2 0x4028_0100 ~0x4028_017F
Gpio3 0x4028_0180 ~0x4028_01FF
Gpio4 0x4028_0200 ~0x4028_027F
Gpio5 0x4028_0280 ~0x4028_02FF
Gpio6 0x4028_0300 ~0x4028_037F
Gpio7 0x4028_0380 ~0x4028_03FF
操作方法1 :
adb root
adb remount
adb shell
lookat -l 8 0x40280080 //打印以 0x40280080 为起始地址的 5个连续的寄存器
lookat -s 0x00004000 0x40280080 //把0x00004000 写入 0x40280080寄存器中
实际操作结果:
xxx-xxx:/ # lookat -l 5 0x40280080
[I] nword = 0x8
ADDRESS | VALUE
-----------+-----------
0x40280080 | 0x00000000
0x40280084 | 0x00004000
0x40280088 | 0x00004000
0x4028008c | 0x0000ffff
0x40280090 | 0x00000000
xxx-xxx:/ #
xxx-xxx:/ # lookat -s 0x00004000 0x40280080
[I] value = 0x4000
xxx-xxx:/ #
2.在linux文件系统中操作gpio设备节点
注意:当前操作方法实际操作时发现基地址为160,但是添加观察的GPIO只能按照144为基地址添加,结合第三点查看gpio状态中的结果可以大致推断,此部分基地址应该存在BUG。
export只能按找 144为基地址加GPIO文件,但是实际GPIO对应的是 160的基地址
/sys/class/gpio
cat gpiochip*/base //查看偏移地址
cat gpiochip*/label // ?
echo 246 >export //添加要看的GPIO编号
cat value //查看GPIO高低电平
cat direction //查看GPIO输入输出状态
实际操作结果:
xxx-xxx:/sys/class/gpio # cat gpiochip*/base //查看偏移地址(基地址是其中之一)
144
160
416
440
464
488
xxx-xxx:/sys/class/gpio # cat gpiochip*/label
sc27xx-eic
40280000.gpio
eic-sync
eic-async
eic-latch
eic-debounce
xxx-xxx:/sys/class/gpio #
xxx-xxx:/sys/class/gpio # echo 184>export //添加要看的GPIO编号(184 为基地址+GPIO编号,如果这里基地址为144,则对应GPIO40)
export gpio281/ gpiochip160/ gpiochip464/
gpio174/ gpio305/ gpiochip416/ gpiochip488/
gpio184/ gpiochip144/ gpiochip440/ unexport
xxx-xxx:/sys/class/gpio #
xxx-xxx:/sys/class/gpio # ls
export gpio184 gpio305 gpiochip160 gpiochip440 gpiochip488
gpio174 gpio281 gpiochip144 gpiochip416 gpiochip464 unexport
xxx-xxx:/sys/class/gpio # cd gpio305/
xxx-xxx:/sys/class/gpio/gpio305 #
xxx-xxx:/sys/class/gpio/gpio305 #
xxx-xxx:/sys/class/gpio/gpio305 #
xxx-xxx:/sys/class/gpio/gpio305 # cat value
0
xxx-xxx:/sys/class/gpio/gpio305 # cat direction
in
xxx-xxx:/sys/class/gpio/gpio305 #
3. 一种查看所有GPIO状态的方法
cat sys/kernel/debug/gpio
实际操作结果:
xxx-xxx:/ # cat /sys/kernel/debug/gpio
gpiochip5: GPIOs 144-159, parent: platform/sc27xx-eic, sc27xx-eic: //sc27xx对应PMIC,GPIO基数为 144
gpio-144 ( |vbus ) in hi IRQ
gpio-145 ( |Power Key ) in hi IRQ
gpio-147 ( |button ) in lo IRQ
gpio-149 ( |detect_mic ) in lo
gpio-152 ( |detect_l ) in lo
gpio-153 ( |bat-detect ) in hi IRQ
gpio-154 ( |Volume Up Key ) in lo IRQ
gpio-156 ( |detect_h ) in lo
gpio-157 ( |detect_all ) in lo IRQ
gpiochip4: GPIOs 160-415, parent: platform/40280000.gpio, 40280000.gpio: //AP,40280000是基地址,GPIO基数为 160
gpio-164 ( |bias_avdd_gpio ) out hi
gpio-165 ( |bias_avee_gpio ) out hi
gpio-168 ( |flash-torch-en-gpios) out lo
gpio-190 ( |power-down-gpios ) out lo
gpio-200 ( |power-down-gpios ) out lo
gpio-201 ( |reset-gpios ) out lo
gpio-204 ( |reset-gpios ) out lo
gpio-206 ( |power-down-gpios ) out lo
gpio-210 ( |reset ) out hi
gpio-213 ( |flash-en-gpios ) out lo
gpio-222 ( |ext_spk_r ) out lo
gpio-238 ( |cd ) in hi IRQ
gpio-249 ( |? ) out lo
gpio-281 ( |adaptive_ts_int ) in hi IRQ
gpio-292 ( |power-down-gpios ) out lo
gpio-304 ( |flash-en-gpios ) out lo
gpio-305 ( |adaptive_ts_rst ) in lo
gpiochip3: GPIOs 416-439, parent: platform/402100c0.gpio, eic-sync:
gpiochip2: GPIOs 440-463, parent: platform/402100a0.gpio, eic-async:
gpiochip1: GPIOs 464-487, parent: platform/40210080.gpio, eic-latch:
gpiochip0: GPIOs 488-511, parent: platform/40210000.gpio, eic-debounce:
gpio-490 ( |Volume Down Key ) in hi IRQ
gpio-492 ( |id ) in lo IRQ
xxx-xxx:/ #