全志R58平台的GPIO引脚控制(草稿)

来源:互联网 发布:php smarty 编辑:程序博客网 时间:2024/05/18 01:45
全志R58平台的GPIO引脚控制




rootroot@cm-System-Product-Name:/home/wwt/vxiaoyu_s5k5eya/lichee/linux-3.4$ make ARCH=arm menuconfig
Device Drivers  --->
-*- GPIO Support  --->
[ ]   /sys/class/gpio/... (sysfs interface)




rootroot@cm-System-Product-Name:/home/wwt/vxiaoyu_s5k5eya/lichee$ find . -name gpio.h
./linux-3.4/arch/arm/mach-sunxi/include/mach/gpio.h
W:\xiaoyu_s5k5eya\lichee\linux-3.4\arch\arm\mach-sunxi\include\mach\gpio.h


得知GPIO号:
#define SUNXI_PINCTRL "sunxi-pinctrl"
#define SUNXI_BANK_SIZE 32
#define SUNXI_PA_BASE 0
#define SUNXI_PB_BASE 32
#define SUNXI_PC_BASE 64
#define SUNXI_PD_BASE 96
#define SUNXI_PE_BASE 128
#define SUNXI_PF_BASE 160
#define SUNXI_PG_BASE 192
#define SUNXI_PH_BASE 224
#define SUNXI_PI_BASE 256
#define SUNXI_PJ_BASE 288
#define SUNXI_PK_BASE 320
#define SUNXI_PL_BASE 352
#define SUNXI_PM_BASE 384
#define SUNXI_PN_BASE 416
#define SUNXI_PO_BASE 448
#define AXP_PIN_BASE 1024


PH11的GPIO引脚号为:
224+11=235




在串口终端中的调试方法:
shell@octopus-f1:/ $ 
shell@octopus-f1:/ $ cd /sys/class/gpio/                                       
shell@octopus-f1:/sys/class/gpio $ ll
--w------- root     root         4096 1970-01-01 09:01 export
lrwxrwxrwx root     root              1970-01-01 09:01 gpiochip0 -> ../../devices/platform/sunxi-pinctrl/gpio/gpiochip0
lrwxrwxrwx root     root              1970-01-01 09:01 gpiochip1024 -> ../../devices/platform/axp-pinctrl/gpio/gpiochip1024
--w------- root     root         4096 1970-01-01 09:01 unexport
shell@octopus-f1:/sys/class/gpio $ 
shell@octopus-f1:/sys/class/gpio $ 




(必须su权限:)
shell@octopus-f1:/sys/class/gpio $ echo 235 > export                           
/system/bin/sh: can't create export: Permission denied
1|shell@octopus-f1:/sys/class/gpio $ su
shell@octopus-f1:/sys/class/gpio # echo 235 > export
shell@octopus-f1:/sys/class/gpio # ll
--w------- root     root         4096 1970-01-02 08:05 export
lrwxrwxrwx root     root              1970-01-02 08:05 gpio235 -> ../../devices/platform/sunxi-pinctrl/gpio/gpio235
lrwxrwxrwx root     root              1970-01-01 09:01 gpiochip0 -> ../../devices/platform/sunxi-pinctrl/gpio/gpiochip0
lrwxrwxrwx root     root              1970-01-01 09:01 gpiochip1024 -> ../../devices/platform/axp-pinctrl/gpio/gpiochip1024
--w------- root     root         4096 1970-01-01 09:01 unexport
shell@octopus-f1:/sys/class/gpio # 




切换到PH11的目录:
shell@octopus-f1:/sys/class/gpio # cd gpio235/                                 
shell@octopus-f1:/sys/class/gpio/gpio235 # ll
-rw-r--r-- root     root         4096 1970-01-02 08:05 active_low
lrwxrwxrwx root     root              1970-01-02 08:05 device -> ../../../sunxi-pinctrl
-rw-r--r-- root     root         4096 1970-01-02 08:05 direction
-rw-r--r-- root     root         4096 1970-01-02 08:05 edge
drwxr-xr-x root     root              1970-01-02 08:05 power
lrwxrwxrwx root     root              1970-01-02 08:05 subsystem -> ../../../../../class/gpio
-rw-r--r-- root     root         4096 1970-01-02 08:05 uevent
-rw-r--r-- root     root         4096 1970-01-02 08:05 value
shell@octopus-f1:/sys/class/gpio/gpio235 # cat direction                       
in
shell@octopus-f1:/sys/class/gpio/gpio235 # echo out > direction                                                             <
shell@octopus-f1:/sys/class/gpio/gpio235 # 
shell@octopus-f1:/sys/class/gpio/gpio235 # cat direction
out
shell@octopus-f1:/sys/class/gpio/gpio235 # # cat value                         
0
shell@octopus-f1:/sys/class/gpio/gpio235 # 
shell@octopus-f1:/sys/class/gpio/gpio235 # echo 1 > value
shell@octopus-f1:/sys/class/gpio/gpio235 # cat value                           
1
shell@octopus-f1:/sys/class/gpio/gpio235 # 
shell@octopus-f1:/sys/class/gpio/gpio235 #