📄 pdd_keypad.c
字号:
return(u32scancode);}/*-----------------------------------------------------------------------*//** You can find the interface description in pdd_keyp.h.*//*----------------------------------------------------------------------- */UINT32 PddKpd_ReadEndKey (void){ UINT32 scancode; NU_SUPERV_USER_VARIABLES; // set auto variable NU_SUPERVISOR_MODE(); // switch to supervisor mode// scancode = KPD_KEYNUM3;// read the value from the PLC where the End-Key is connected. scancode = PCL_01; // read scancode from PCL_01 register NU_USER_MODE(); // switch to user mode return (scancode);}/*-----------------------------------------------------------------------*//** You can find the interface description in pdd_keyp.h.*//*----------------------------------------------------------------------- */UINT8 PddKpd_WhichIntOccurred(void){ return (mg_u8IntOccurred);}/*-----------------------------------------------------------------------*//** You can find the interface description in pdd_keyp.h.*//*----------------------------------------------------------------------- */void PddKpd_EnableKeypadInt0_3(void){ NU_SUPERV_USER_VARIABLES; // set auto variable NU_SUPERVISOR_MODE(); // switch to supervisor mode ENABLE_KEYPAD_INT0; ENABLE_KEYPAD_INT3; NU_USER_MODE(); // switch to user mode}/*-----------------------------------------------------------------------*//** You can find the interface description in pdd_keyp.h.*//*----------------------------------------------------------------------- */void PddKpd_DisableKeypadInt0_3(void){ NU_SUPERV_USER_VARIABLES; // set auto variable NU_SUPERVISOR_MODE(); // switch to supervisor mode DISABLE_KEPYAD_INT0; DISABLE_KEPYAD_INT3; NU_USER_MODE(); // switch to user mode}/*-----------------------------------------------------------------------*//** You can find the interface description in pdd_keyp.h.*//*----------------------------------------------------------------------- */UINT8 PddKpd_InterruptIsDisabled(void){ if( ( (KPD_SRC0 & KPD_SRC_X_SRE) & (KPD_SRC3 & KPD_SRC_X_SRE) ) == 0) { // Keypad interrupt 0 and 3 are disabled return TRUE; } return FALSE;}/* ----------------------------------------------------------------------------- IMPLEMENTATION SECTION LOCAL FUNCTIONS------------------------------------------------------------------------------*///**********************************//* Port Configuration *//**********************************/*-----------------------------------------------------------------------*//** Port configuration for keypad. Register at portmanager and configure the port control logic for the keypad. \param none \return none*//*----------------------------------------------------------------------- */STATIC void PddKpd_KeypadPortConfig(void){ KeypadPortMgrID = PortMgr_Register (); // registering at portmanager PortMgr_AddPurposes (KeypadPortMgrID, PortPurposeListKeypad, sizeof(PortPurposeListKeypad)/sizeof(T_PortMgr_PurposeConfig)); return;}/*-----------------------------------------------------------------------*//** Keypad Interrupt configuration. Notify all interrupt service functions (LISRs) to the interrupt handler. All interrrupts have the same type: INT_TYPE_OS_MANAGED_IRQ, because a HISR is called from the LISR. \param none \return none*//*----------------------------------------------------------------------- */STATIC void PddKpd_LisrConfig(void){ T_Int_Config keyp_int0_new, keyp_int0_old; T_Int_Config keyp_int3_new, keyp_int3_old;//------ Keypad INT0: Key pressed, no of pressed keys changed ---------------- keyp_int0_new.itype = INT_TYPE_OS_MANAGED_IRQ; // managed by OS, because HISR is called keyp_int0_new.prio.osManagedIrq = INT_PRIO_2; // interrupt prio keyp_int0_new.handler = PddKpd_Int0Lisr; // interrupt handler for Keypad INT0, LISR Int_ConfigSource(INT_SRC_KEYPAD_IRQ1,&keyp_int0_new,&keyp_int0_old); //config interrupt//------ Keypad INT3: long key released ------------------------------------- keyp_int3_new.itype = INT_TYPE_OS_MANAGED_IRQ; // managed by OS, because HISR is called keyp_int3_new.prio.osManagedIrq = INT_PRIO_2; // interrupt prio keyp_int3_new.handler = PddKpd_Int3Lisr; // interrupt handler for Keypad INT3, LISR Int_ConfigSource(INT_SRC_KEYPAD_IRQ4,&keyp_int3_new,&keyp_int3_old); //config interrupt return;}//****************************************//* LISRs for all used keypad interrupts *//****************************************/*-----------------------------------------------------------------------*//** LISR, Interrupt handler for: keypad INT0. INT0 occurred if a new key is detected by the keypad hardware or in case more then one key is pressed, the number of keys has changed. What is done in the LISR: - clear interrupt - save occurred keypad interrupt type - read and save scancode - activate keypad HISR \param Interrupt source \return none*//*----------------------------------------------------------------------- *//*lint -e715*/STATIC void PddKpd_Int0Lisr(T_Int_Source Kpd_Int0_Source){ STATUS nuStatus;//---- disable interrupt 0 and 3 --------------------------------------- DISABLE_KEPYAD_INT0; DISABLE_KEPYAD_INT3;//---- save interrupt reason ------------------------------------------- mg_u8IntOccurred = KEYPAD_INTERRUPT_0;//---- read scancode --------------------------------------------------- if(mg_u32scancode1 != 0) { // The keypad HISR is pending and a new interrupt occured. // Leave the interrupt service routine without clearing the interrupt. // We have to wait until the keypad HISR was called. CLEAR_KEYPAD_INT0; ENABLE_KEYPAD_INT0; ENABLE_KEYPAD_INT3; SEXIT(LISR0_SCANCODE1_NOT_READ); return; } mg_u32scancode1 = PddKpd_ReadKeynum1(); // standard key if(mg_u32scancode3 != 0) { // The keypad HISR is pending and a new interrupt occured. // Leave the interrupt service routine without clearing the interrupt. // We have to wait until the keypad HISR was called. CLEAR_KEYPAD_INT0; ENABLE_KEYPAD_INT0; ENABLE_KEYPAD_INT3; SEXIT(LISR0_SCANCODE3_NOT_READ); return; } mg_u32scancode3 = PddKpd_ReadKeynum3(); // special key //---- activate HISR --------------------------------------------------- nuStatus = NU_Activate_HISR(pKeypHisr); // activate HISR if(nuStatus != NU_SUCCESS) { // The keypad HISR is pending and a new interrupt occured. // Leave the interrupt service routine without clearing the interrupt. // We have to wait until the keypad HISR was called. EXIT(NU_HISR_ACTIVATION_FAILED_0); }//---- clear interrupt ------------------------------------------------- CLEAR_KEYPAD_INT0; return;}/*lint +e715*//*-----------------------------------------------------------------------*//** LISR, Interrupt handler for: keypad INT3. INT3 occurred if a long key was released. What is done in the LISR: - clear interrupt - save occurred keypad interrupt type - read and save scancode - activate keypad HISR \param Interrupt source \return none*//*----------------------------------------------------------------------- *//*lint -e715*/STATIC void PddKpd_Int3Lisr(T_Int_Source Kpd_Int3_Source){ STATUS nuStatus;//---- disable interrupt 0 and 3 --------------------------------------- DISABLE_KEPYAD_INT0; DISABLE_KEPYAD_INT3;//---- save interrupt reason ------------------------------------------- mg_u8IntOccurred = KEYPAD_INTERRUPT_3;//---- read scancode --------------------------------------------------- if(mg_u32scancode1 != 0) { // The keypad HISR is pending and a new interrupt occured. // Leave the interrupt service routine without clearing the interrupt. // We have to wait until the keypad HISR was called. CLEAR_KEYPAD_INT3; ENABLE_KEYPAD_INT0; ENABLE_KEYPAD_INT3; SEXIT(LISR3_SCANCODE1_NOT_READ); return; } mg_u32scancode1 = PddKpd_ReadKeynum1(); // standard key if(mg_u32scancode3 != 0) { // The keypad HISR is pending and a new interrupt occured. // Leave the interrupt service routine without clearing the interrupt. // We have to wait until the keypad HISR was called. CLEAR_KEYPAD_INT3; ENABLE_KEYPAD_INT0; ENABLE_KEYPAD_INT3; SEXIT(LISR3_SCANCODE3_NOT_READ); return; } mg_u32scancode3 = PddKpd_ReadKeynum3(); // special key//---- activate HISR ---------------------------------------------------- nuStatus = NU_Activate_HISR(pKeypHisr); // activate HISR if(nuStatus != NU_SUCCESS) { // The keypad HISR is pending and a new interrupt occured. // Leave the interrupt service routine without clearing the interrupt. // We have to wait until the keypad HISR was called. EXIT(NU_HISR_ACTIVATION_FAILED_3); }//---- clear interrupt ------------------------------------------------- CLEAR_KEYPAD_INT3; return;}/*lint +e715*//*-----------------------------------------------------------------------*//** Configuration of keypad kernel. Configure KPD_CONFIG register (Debounce time and long key press time). \param none \return none*//*----------------------------------------------------------------------- */STATIC void PddKpd_ConfigKeypadKernel (void){// NU_SUPERV_USER_VARIABLES; // set auto variable// NU_SUPERVISOR_MODE(); // switch to supervisor mode KPD_CONFIG &= CLEAR_REGISTER; // clear register value (reset values is 0x000006400)! KPD_CONFIG |= (DEBOUNCE_TIME|LONG_KEY_TIME); // config debounce- and long key pressed time.// NU_USER_MODE(); // switch to user mode return;}/*-----------------------------------------------------------------------*//** Read scancode for standard keys out of HW-register KEYNUM1. This function is called from LISR. \param none \return UINT32 Scancode for standard keys.*//*----------------------------------------------------------------------- */UINT32 PddKpd_ReadKeynum1 (void){ UINT32 scancode; scancode = KPD_KEYNUM1; // read scancode return (scancode);}/*-----------------------------------------------------------------------*//** Read scancode for special keys out of HW-register KEYNUM3. This function is called from LISR. \param none \return UINT32 Scancode for special keys.*//*----------------------------------------------------------------------- */UINT32 PddKpd_ReadKeynum3 (void){ UINT32 scancode; scancode = KPD_KEYNUM3; // read scancode return (scancode);}/* ----------------------------------------------------------------------------- END OF FILE %name%------------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -