/**************************************************************************** * * Called to perform module initialization when the module is loaded * ***************************************************************************/ static int __devinit bcm_gpio_kp_probe(struct platform_device *pdev) { int ret; struct CBLK *bcm_kp; struct BCM_KEYPAD_PLATFORM_DATA *pdata = pdev->dev.platform_data; struct BCM_GPIO_KEYMAP *keymap_p = pdata->keymap; BCMKP_DBG(KERN_NOTICE "bcm_gpio_kp_probe\n"); if(( bcm_kp = kmalloc(sizeof(*bcm_kp), GFP_KERNEL)) == NULL ) { printk(KERN_ERR "%s(%s:%u)::Failed to allocate keypad structure...\n", __FUNCTION__, __FILE__, __LINE__); return -ENOMEM; } memset( bcm_kp, 0, sizeof(*bcm_kp)); if(( bcm_kp->input_dev = input_allocate_device()) == NULL ) { printk(KERN_ERR "%s(%s:%u)::Failed to allocate input device...\n", __FUNCTION__, __FILE__, __LINE__); return -ENOMEM; } platform_set_drvdata(pdev, bcm_kp); /* Setup input device */ set_bit(EV_KEY , bcm_kp->input_dev->evbit); set_bit(EV_REP, bcm_kp->input_dev->evbit); bcm_kp->input_dev->name = "keypad"; bcm_kp->input_dev->phys = "keypad/input0"; bcm_kp->input_dev->id.bustype = BUS_HOST; bcm_kp->input_dev->id.vendor = 0x0001; bcm_kp->input_dev->id.product = 0x0001; bcm_kp->input_dev->id.version = 0x0100; bcm_kp->input_dev->keycode = bcm_kp->keycode; bcm_kp->input_dev->keycodesize = sizeof( bcm_kp->keycode[0] ); bcm_kp->input_dev->keycodemax = ARRAYSIZE( bcm_kp->keycode ) ; memset( bcm_kp->prevDown, 0, sizeof( bcm_kp->prevDown )); #ifdef SET_GPIO_KEYPAD /* If any special hardware specific initilization is needed before gpios can be used, please put them under this macro. e.g in BCM2153 chip, by default the keypad gpios goes through keypad controller and this macro switchs them back to be used as regular gpios. */ SET_GPIO_KEYPAD; #endif /* Setup GPIO and Interrupt handler */ bcm_kp->direct_key_col_index = -1; bcm_kp->key_count = pdata->array_size; bcm_kp->row_count = CreateRowArray( bcm_kp, keymap_p ); bcm_kp->col_count = CreateColArray( bcm_kp, keymap_p ); CreateKeyMap( bcm_kp, keymap_p ); SetColOutput( bcm_kp->keyColArray, bcm_kp->col_count ); ret = SetRowInput( bcm_kp->keyRowArray, bcm_kp->row_count, bcm_kp ); if (ret < 0) { printk(KERN_ERR "%s(%s:%u)::Unable to register GPIO-keypad IRQ\n", __FUNCTION__, __FILE__, __LINE__); goto free_irq; } ret = input_register_device(bcm_kp->input_dev); if (ret < 0) { printk(KERN_ERR "%s(%s:%u)::Unable to register GPIO-keypad input device\n", __FUNCTION__, __FILE__, __LINE__); goto free_dev; } /* Initialization Finished */ BCMKP_DBG(KERN_DEBUG "BCM keypad initialization completed...\n"); return (ret); free_dev: input_unregister_device(bcm_kp->input_dev); input_free_device(bcm_kp->input_dev); free_irq: free_all_irqs( bcm_kp ); return -EINVAL; }
//============================================================================== void KeyBoard_Scan(void) { uint8_t i; uint32_t tmp; // if(Sys_Start_Flag == 0)return; if(KeyBoardType.flagfull == 1)return; if(SysTickCnt - KeyBoardType.scanticks < KEYSCANDLY)return; KeyBoardType.scanticks = SysTickCnt; switch(KeyBoardType.status) { case 0: SetRowInput(); KeyBoardType.status++; break; case 1: tmp = GetRowValue(); if(tmp != 0) { KeyBoardType.code = tmp; KeyBoardType.status++; } else { KeyBoardType.code = 0; } KeyBoardType.keycnt = 0; break; case 2: tmp = GetRowValue(); if(tmp == KeyBoardType.code) { if(++KeyBoardType.keycnt > KEYSCANCNT) { KeyBoardType.status++; } } else { KeyBoardType.keycnt = 0; KeyBoardType.code = 0; KeyBoardType.status = 1; } break; case 3: SetLineInput(); KeyBoardType.status++; break; case 4: tmp = GetLineValue(); if(tmp != 0) { KeyBoardType.code += tmp; KeyBoardType.status++; } else { KeyBoardType.code = 0; KeyBoardType.status = 0; } KeyBoardType.keycnt = 0; break; case 5: tmp = GetLineValue(); if(tmp == (KeyBoardType.code&0xf0)) { if(++KeyBoardType.keycnt > KEYSCANCNT) { KeyBoardType.status++; } } else { KeyBoardType.keycnt = 0; KeyBoardType.code = 0; KeyBoardType.status = 0; } break; case 6: for(i = 0;i < sizeof(g_KeyCode);i++) { if(KeyBoardType.code == g_KeyCode[i]) { break; } } if(i >= sizeof(g_KeyCode)) { KeyBoardType.keycnt = 0; KeyBoardType.code = 0; KeyBoardType.status = 0; break; } KeyBoardType.value[KeyBoardType.product] = i; i = (KeyBoardType.product+1)%KEYMAXNUM; if(i == KeyBoardType.consume) { KeyBoardType.flagfull = 1; } else { KeyBoardType.product = i; } KeyBoardType.status++; FlipOutput(LED2); // BUZZER_ON; // SysBlockTick.buzzercnt = BUZZERDLY; break; case 7: if(KeyBoardType.dly++ > KEYRPTDLY/KEYSCANDLY) { KeyBoardType.dly = 0; KeyBoardType.status = 0; KeyBoardType.keycnt = 0; KeyBoardType.code = 0; } break; default:break; } }