展锐矩阵键盘

展锐支持矩阵键盘,有KEYIN,KEYOUT的GPIO定义。

components/hal/include/平台名字/key_padmap_平台名字.csv

为配置文件,如果找不到类似的配置文件,说明平台不支持。

那么没有办法也可以用linux下面的matrix_key.c来做。

matrix key的核心思想,是用输入口做外部中断口,有按键按下的时候会进入中断服务程序

matrix_keypad_interrupt

在这个中断服务程序中会启动

matrix_keypad_scan

matrix_keypad_scan中会依次将COL线输出低电平,然后读row的状态,从而确定是哪一个按键按下。

	/* assert each column and read the row status out */
	for (col = 0; col < pdata->num_col_gpios; col++) {

		activate_col(pdata, col, true);

		for (row = 0; row < pdata->num_row_gpios; row++)
			new_state[col] |=
				row_asserted(pdata, row) ? (1 << row) : 0; //读出row的状态

		activate_col(pdata, col, false);  //依次输出低
	}

	for (col = 0; col < pdata->num_col_gpios; col++) {
		uint32_t bits_changed;

		bits_changed = keypad->last_key_state[col] ^ new_state[col];
		if (bits_changed == 0)
			continue;

		for (row = 0; row < pdata->num_row_gpios; row++) {
			if ((bits_changed & (1 << row)) == 0)
				continue;

			code = MATRIX_SCAN_CODE(row, col, keypad->row_shift);  //根据col,row定位按键
			input_event(input_dev, EV_MSC, MSC_SCAN, code);
			input_report_key(input_dev,   //上报按键键值
					 keycodes[code],
					 new_state[col] & (1 << row));
		}
	}
	input_sync(input_dev);

这里需要注意的是,要定义好dts中的内容

      matrix-keypad {
           compatible = "gpio-matrix-keypad";
           debounce-delay-ms = <5>;
           col-scan-delay-us = <2>;
           drive-inactive-cols = <1>;  //轮询后,col输出低,不要变成输入(高阻)态
           gpio-activelow = <1>;   // col输出低有效

           row-gpios = <&ap_gpio 25 0
                        &ap_gpio 26 0>;  //原始脚位数

           col-gpios = <&ap_gpio 21 0
                        &ap_gpio 22 0
                        &ap_gpio 23 0>;  //原始脚位的数

           linux,keymap = <0x0000008B    //前16bit为row,跟住16bit为col数,后面32bit为键值
                           0x0100009E
                           0x00010069
                           0x0101006A
                           0x0002001C
                           0x0102006C>;
       };

在deconfig中打开编译选项,参与编译就可以用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值