一、硬件连接
APP ---- PH2
HOME ---- PH3
BACK ---- PH4
二、sys_config.fex
GPIO描述形式为:
端口+组内序号+功能分配+内部电阻(0:No Pull, 1: Pull Up , 2: Pull Down,默认0)
+ 驱动能力(分4级,0123,默认0)+输出电平(0,1 设置为输出时有效)
下面程序中就是:PH3 ,功能分配为EINT3,其他为默认值,即为中断输入
;----------------------------------------------------------------------------------
;gpio key configuration
;----------------------------------------------------------------------------------
[gpio_group]
KEY_HOME = port:PH03<6><default><default><1>
;----------------------------------------------------------------------------------
;recovery key
;----------------------------------------------------------------------------------
[recovery_key]
key_max = 0x07
key_min = 0x02
;----------------------------------------------------------------------------------
;fastboot key
;----------------------------------------------------------------------------------
[fastboot_key]
key_max = 0x0f
key_min = 0x0b
三、源码(bugid:17404)
路径:/u-boot-2014.07/board/sunxi/common/board_common.cint get_home_key_value(void)
{
int ret;
user_gpio_set_t gpio_reverse;
int gpio_value = 0;
static __u32 gpio_handle;
ret = script_parser_fetch("gpio_group", "KEY_HOME", (int *)&gpio_reverse, sizeof(user_gpio_set_t)/4);
//根据sys_config.fex键值来获取HOME键的信息
if(!ret)
{
gpio_reverse.mul_sel = 0; //set input type,将home键设置为输入
gpio_handle = gpio_request(&gpio_reverse, 1); //返回HOME键的句柄
if(gpio_handle)
{
gpio_value = gpio_read_one_pin_value(gpio_handle, 0);
}
pr_msg("gpio key of home value is %d\n", gpio_value);
return gpio_value;
}
pr_msg("get the key of home value is wrong!\n");
return -1;
}