假设是3行3列的按键,press_mask和release_mask这样算的含义是什么?
static void keypad_timer_handler(unsigned long data)
{
u32 press_mask;
u32 release_mask;
u32 restart_timer = 0;
int i, col;
struct s3c_keypad *pdata = (struct s3c_keypad *)data;
struct input_dev *dev = pdata->dev;
keypad_scan();
for (col = 0; col < KEYPAD_COLUMNS; col++) {
press_mask = ((keymask[col] ^ prevmask[col]) & keymask[col]);
release_mask = ((keymask[col] ^ prevmask[col]) & prevmask[col]);
i = col * KEYPAD_ROWS;
while (press_mask) {
if (press_mask & 1) {
input_report_key(dev, pdata->keycodes[i], 1);
printk("key Pressed : key %d map %d\n",
i, pdata->keycodes[i]);
}
press_mask >>= 1;
i++;
}
i = col * KEYPAD_ROWS;
while (release_mask) {
if (release_mask & 1) {
input_report_key(dev, pdata->keycodes[i], 0);
printk("key Released : %d map %d\n",
i, pdata->keycodes[i]);
}
release_mask >>= 1;
i++;
}
prevmask[col] = keymask[col];
restart_timer |= keymask[col];
}
if (restart_timer) {
mod_timer(&keypad_timer, jiffies + HZ/10);
} else {
writel(KEYIFCON_INIT, key_base + S3C_KEYIFCON);
is_timer_on = false;
}
}
------解决方案--------------------
完成按键的什么功能?可以侦测按下,抬起动作?一般简单的按键就检测到按下动作,没释放动作。看起来完成按键的事件蛮复杂的,如果能知道目的,解释起来应该很好办了。