大家好,又见面了,我是你们的朋友全栈君。
mx53 linux 用gpio模拟matrix keypad需要做的工作
1、在配置内核驱动的时候添加 gpiomatrix keypad
DeviceDrivers —>
Inputdevice support —>
Keyboards —>
<*> GPIO driven matrix keypad support
2、在mx53_loco.c文件中添加代码
static const uint32_t mx53_keymap[] = {
KEY(0,0, KEY_0),
// KEY(0,1, KEY_A),
// KEY(0,2, KEY_3),
// KEY(0,3, KEY_5),
// KEY(0,4, KEY_6),
// KEY(0,5, KEY_7),
// KEY(0,6, KEY_9),
// KEY(1,0, KEY_9),
// KEY(1,1, KEY_E),
// KEY(1,2, KEY_4),
// KEY(1,3, KEY_R),
// KEY(1,4, KEY_Y),
// KEY(1,5, KEY_8),
// KEY(1,6, KEY_I),
// KEY(2,0, KEY_TAB),
// KEY(2,1, KEY_Q),
// KEY(2,2, KEY_E),
// KEY(2,3, KEY_T),
// KEY(2,4, KEY_G),
// KEY(2,5, KEY_U),
// KEY(2,6, KEY_J),
};
static struct matrix_keymap_data mx53_keymap_data= {
.keymap = mx53_keymap,
.keymap_size = ARRAY_SIZE(mx53_keymap),
};
static const int mx53_row_gpios[] =
{GPIO_4_0};
static const int mx53_col_gpios[] =
{GPIO_4_1};
static struct matrix_keypad_platform_datamx53_pdata = {
.keymap_data = &mx53_keymap_data,
.row_gpios = mx53_row_gpios,
.col_gpios = mx53_col_gpios,
.num_row_gpios = ARRAY_SIZE(mx53_row_gpios),
.num_col_gpios = ARRAY_SIZE(mx53_col_gpios),
.col_scan_delay_us = 10,
.debounce_ms = 80,
// .wakeup = 1,
.active_low = 1,
};
static struct platform_device mx53_device ={
.name = “matrix-keypad”,
.id = -1,
.dev = {
.platform_data= &mx53_pdata,
},
};
static void __initmx53_add__matrix_keypad(void)
{
platform_device_register(&mx53_device);
}
在static void __init mxc_board_init(void)函数中添加代码
mx53_add__matrix_keypad();
系统启动后,运行qt程序时,按下按键有如下打印消息
keycode is 48 unicode is 48 modifiers is 0 isPress is 1,autoRepeat is 0 keycode is 48 unicode is 48 modifiers is 0 isPress is 0,autoRepeat is 0
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/146244.html原文链接:https://javaforall.cn