s3c-keypad.c矩阵键盘代码有些不懂!
本帖最后由 fjlhlonng 于 2013-02-28 14:52:05 编辑
假设是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;
}
}