当前位置: 代码迷 >> 驱动开发 >> 嵌入式linux矩阵键盘驱动解决思路
  详细解决方案

嵌入式linux矩阵键盘驱动解决思路

热度:44   发布时间:2016-04-28 10:57:42.0
嵌入式linux矩阵键盘驱动
ARM:AM3517
linux2.6.37
TI官方开发板AM3517EVM

我想移植一个8*5的GPIO矩阵键盘,在linux源码/drivers/input/目录下有很多种键盘驱动程序,但是
能用到自己项目上的似乎只有matrix-keypad键盘驱动,我在board-am3517evm.c中定义好了键盘资源,如下:

static const unsigned int matrix_keypad_cols[] = {128,129,130,131,132};
static const unsigned int matrix_keypad_rows[] = {120,121,122,123,124,125,126,127};
static uint32_t am3505_keymap[] __initdata = 
{
  //KEY(row, col, keycode)
  KEY(0,0, KEY_F1), KEY(0,1, KEY_1), KEY(0,2, KEY_4), KEY(0,3, KEY_7), KEY(0,4,KEY_PROG1),
  KEY(1,0, KEY_F2), KEY(1,1, KEY_2), KEY(1,2, KEY_5), KEY(1,3, KEY_8),KEY(1,4,KEY_PROG2), 
  KEY(2,0, KEY_F3), KEY(2,1, KEY_3), KEY(2,2, KEY_6), KEY(2,3, KEY_9),KEY(2,4,KEY_PROG3), 
  KEY(3,0, KEY_F4),KEY(3,1, KEY_0),KEY(3,2,KEY_DOT),KEY(3,3,KEY_HELP),KEY(3,4,KEY_PROG4), 
  KEY(4,0, KEY_F5), KEY(4,1, KEY_DELETE), KEY(4,2, KEY_INSERT), KEY(4,3, KEY_SETUP), KEY(4,4, KEY_B),
  KEY(5,0, KEY_F6), KEY(5,1, KEY_HOMEPAGE), KEY(5,2, KEY_ESC), KEY(5,3, KEY_LEFT), KEY(5,4, KEY_W),
  KEY(6,0, KEY_F7), KEY(6,1, KEY_END), KEY(6,2, KEY_UP), KEY(6,3, KEY_ENTER), KEY(6,4, KEY_DOWN),
  KEY(7,0, KEY_F8), KEY(7,1, KEY_PAGEUP), KEY(7,2, KEY_PAGEDOWN), KEY(7,3, KEY_RIGHT), KEY(7,4, KEY_POWER),
};
static struct matrix_keymap_data am3505_keymap_data __initdata = 
{
  .keymap = am3505_keymap,
  .keymap_size =ARRAY_SIZE(am3505_keymap),
};
static struct matrix_keypad_platform_data am3505_keypad_data __initdata = 
{
  .keymap_data = &am3505_keymap_data,
  .col_gpios = matrix_keypad_cols,
  .row_gpios = matrix_keypad_rows,
  .num_col_gpios = ARRAY_SIZE(matrix_keypad_cols),
  .num_row_gpios = ARRAY_SIZE(matrix_keypad_rows),
  .col_scan_delay_us = 10,
  .debounce_ms = 80,
// .wakeup = 1,
  .active_low = 1,
  // .no_autorepeat = 1,
};
配置GPIO口
  OMAP3_MUX(SDMMC1_CLK, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLDOWN),
OMAP3_MUX(SDMMC1_CMD, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLDOWN),
OMAP3_MUX(SDMMC1_DAT0, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLDOWN),
OMAP3_MUX(SDMMC1_DAT1, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLDOWN),
  OMAP3_MUX(SDMMC1_DAT2, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLDOWN),
OMAP3_MUX(SDMMC1_DAT3, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLDOWN),
OMAP3_MUX(SDMMC1_DAT4, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLDOWN),
OMAP3_MUX(SDMMC1_DAT5, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLDOWN),

  OMAP3_MUX(SDMMC1_DAT6, OMAP_MUX_MODE4 | OMAP_PIN_OUTPUT),
OMAP3_MUX(SDMMC1_DAT7, OMAP_MUX_MODE4 | OMAP_PIN_OUTPUT),
  OMAP3_MUX(SDMMC2_CLK, OMAP_MUX_MODE4 | OMAP_PIN_OUTPUT),
OMAP3_MUX(SDMMC2_CMD, OMAP_MUX_MODE4 | OMAP_PIN_OUTPUT),
  OMAP3_MUX(SDMMC2_DAT0, OMAP_MUX_MODE4 | OMAP_PIN_OUTPUT),

加入到设备列表中
static struct platform_device *am3517_evm_devices[] __initdata = {
&am3517_evm_dss_device,
  &matrix_device_keypad,
};

1 请问以上的键盘代码移植是否有问题?
2 板卡启动后,行按键中断可以响应,在matrix-keypad.c文件函数matrix_keypad_interrupt中
打印调试信息printk();说明可以响应行中断,schedule_delayed_work(&keypad->work,msecs_to_jiffies(keypad->pdata->debounce_ms));中的keypad->pdata->debounce_ms值为负值,我在上面明明设置抖动时间为80;不知道是说明原因?

------解决方案--------------------
__initdata只在内核初始化的时候分配空间,进入文件系统后就会释放掉内存,去掉这个看看