📄 add_keypad.c
字号:
/** @file *//* ----------------------------------------------------------------------------Copyright (C) Siemens AG 1994-2001 * ALL RIGHTS RESERVED This software is protected by the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred. The information contained in this document is considered the CONFIDENTIAL and PROPRIETARY information of Siemens AG and may not be disclosed or discussed with anyone who is not employed by Siemens AG, unless the individual / company (i) has an express need to know such information, and (ii) disclosure of information is subject to the terms of a duly executed Confidentiality and Non-Disclosure Agreement between Siemens AG and the individual / company.Created using template RCSfile: templ_c.c,v, Revision: 1.7, genxfile V1.9.AUTHOR Holger Hollenberg.FILENAME add_keypad.c.TODO - deact function - move kypad manager init function to an action function.VERSION 01.03.10.DATE 2004-04-15.SHORT_DESCR Keypad device driver, Keypad state machine (Keypad-HISR).SW_COMPONENT ADD device driver.SW_TYPE DEVICE_DRIVER.EXIT_CODES 0xD112 : UNEXPECTED_KEYPAD_STATE \ 0xD113 : STANDARD_KEY_SCANCODE_NOT_FOUND_IN_TABLE \ 0xD114 : SPECIAL_KEY_SCANCODE_NOT_FOUND_IN_TABLE \ 0xD115 : MULTIPLE_KEY_DETECTION_BUFFER_OVERFLOW \ 0xD116 : WRONG_SECOND_STANDARD_KEY_IN_SINGLE_KEY_MODE \ 0xD117 : WRONG_SECOND_SPECIAL_KEY_IN_SINGLE_KEY_MODE \ 0xD118 : WRONG_MULTIPLE_STANDARD_KEY_IN_SINGLE_KEY_MODE_CASE_2 \ 0xD119 : WRONG_MULTIPLE_STANDARD_KEY_IN_SINGLE_KEY_MODE_CASE_3 \ 0xD11A : WRONG_MULTIPLE_SPECIAL_KEY_IN_SINGLE_KEY_MODE_CASE_2 \ 0xD11B : WRONG_MULTIPLE_SPECIAL_KEY_IN_SINGLE_KEY_MODE_CASE_3 \ 0xD11C : KEYPAD_INTERRUPS_NOT_DISABLED \.CHANGE_CONTROL Version Date Changed by Reason of change--------------------------------------------------------------------------------01.00.00 2003-05-02 H. Hollenberg (KLF) Initial Version01.00.01 2003-05-05 Michael Paar (MCH) Moved keycode tables to C file 01.01.00 2003-05-08 H. Hollenberg (KLF) add scancodes in scancode table for EVA-BOARD C65-Plattform, MAMBA-IFX01.01.01 2003-05-12 H. Hollenberg (KLF) add KEYCODE typedef for keycode tabel.01.02.00 2003-05-14 H. Hollenberg (KLF) Activate Startbit Process for application layer after a detected key was written into the keypad buffer, in ddkeyp_WriteKeyToBuffer().01.03.00 2003-06-05 H. Hollenberg (KLF) Add and activate double key detection. Now it is possible to detect two keys at the same time. A switch between single and double key mode is prepared but not activated.01.03.01 2003-06-24 H. Hollenberg (KLF) Modify keycode table for Viper testboard.01.03.02 2003-06-27 H. Hollenberg (KLF) Move keycode table to special directory for project dependent data: C_devhigh/S_devhighcfg/keypad/ . Deactivate Startbit process for application.01.03.03 2003-07-28 P. Henn (KLF) activate startit process for application01.03.04 2003-11-03 H. Hollenberg (KLF) Add BFC functionality.01.03.05 2003-11-13 H.Hollenberg (KLF) Changes for keypad manager integration.01.03.06 2003-11-20 H. Hollenberg (KLF) Add new access for keycode table. Add Scancode_SwitchKeycodeTable() to init function.01.03.07 2003-12-04 H. Hollenberg (KLF) Move some Init functions to Keypad_ActionFunction(): Keypad_BfcInit(), KeypadManager_Init() and Scancode_SwitchKeycodeTable().01.03.08 2004-02-12 H. Hollenberg (KLF) Add function call to enable keypad interrupts in keypad HISR, PddKpd_EnableKeypadInt0_3(). Test if HISR is called the keypad interrupts are disabled.01.03.09 2004-03-23 H. Hollenberg (KLF) Bugfix Keypad driver. Switch off after multiple key press.01.03.10 2004-04-15 H.Hollenberg (KLF) Bugfix: Switch on problem, do not activate startbit process from application layer before it is initalized.G F B step up: Generation / Feature / Bugfix------------------------------------------------------------------------------*//* ----------------------------------------------------------------------------- INCLUDES------------------------------------------------------------------------------*/#include <global.h>#include "gbs.h" // interface to GBS emulation#include "gbsext.h"#include "procid.h" // interface to all process ids, includes mopi_groupdef_icl0.h#include "keypad_manager.h"// interface to keypad manager#include "add_keyp.h" // component interface from ADD keypad driver #include "pdd_keyp.h" // interface to ADD keypad device driver#include "scancode.h" // interface to keycode table/* ----------------------------------------------------------------------------- EXIT DEFINES------------------------------------------------------------------------------*/#define TASK_NR 0xD1#define MODUL_NR 0x01#include "exit.h"/* ----------------------------------------------------------------------------- DEFINES------------------------------------------------------------------------------*//** Keypad Modes */enum{ eSingleKeyMode, eDoubleKeyMode}TKeyMode;/** States for keypad state machine */enum{ eIdle, eFirstStandardKey, eFirstSpecialKey, eSecondStandardKey, eSecondSpecialKey, eMultipleStandardKey, eMultipleSpecialKey}TKeyMainStates;/** Key status */enum{ eKeyPressed, eKeyReleased, eKeyPressedOldKeyReleased, eKeyAlreadyPressed}TKeyStatus;/** (S)EXIT Defines */#define UNEXPECTED_KEYPAD_STATE (2)#define STANDARD_KEY_SCANCODE_NOT_FOUND_IN_TABLE (3)#define SPECIAL_KEY_SCANCODE_NOT_FOUND_IN_TABLE (4)#define MULTIPLE_KEY_DETECTION_BUFFER_OVERFLOW (5)#define WRONG_SECOND_STANDARD_KEY_IN_SINGLE_KEY_MODE (6)#define WRONG_SECOND_SPECIAL_KEY_IN_SINGLE_KEY_MODE (7)#define WRONG_MULTIPLE_STANDARD_KEY_IN_SINGLE_KEY_MODE_CASE_2 (8)#define WRONG_MULTIPLE_STANDARD_KEY_IN_SINGLE_KEY_MODE_CASE_3 (9)#define WRONG_MULTIPLE_SPECIAL_KEY_IN_SINGLE_KEY_MODE_CASE_2 (0xA)#define WRONG_MULTIPLE_SPECIAL_KEY_IN_SINGLE_KEY_MODE_CASE_3 (0xB)#define KEYPAD_INTERRUPS_NOT_DISABLED (0xC)/** Buffer size for multiple key detection*/#define MULTIPLE_KEY_BUFFER_SIZE (32)/** Init value for keynum (scancode) history. */#define NO_KEY_SCANCODE (0xFFFFFFFF)/* ----------------------------------------------------------------------------- TYPES------------------------------------------------------------------------------*//** Define key parameters. * In the view of the keypad device driver a key is represented by: * - single scancode * - key type: standard or special key */typedef struct{ UINT32 u32Scancode; UINT8 u8Type;}TKey;/* ----------------------------------------------------------------------------- FILE LOCAL CONSTANTS------------------------------------------------------------------------------*//* ----------------------------------------------------------------------------- FILE LOCAL VARIABLES------------------------------------------------------------------------------*//** Keypad Mode * Possible Keypad modes are * Single Key detection or * Double Key detection. */STATIC UINT8 mg_u8KeypadMode;/** State variable for keypad state machine. */STATIC UINT8 mg_u8KeyState;/** Key variable: all known Informations of a detected key are stored in this variable. * Use Key1 for single key detection. * Use Key2 for double press keys. */TKey Key1, Key2;/** Scancode and scancode history from KEYNUM1 register (standard keys) */STATIC UINT32 mg_u32CurrentKenum1, mg_u32OldKenum1;/** Scancode and scancode history from KEYNUM3 register (special keys) */STATIC UINT32 mg_u32CurrentKenum3, mg_u32OldKenum3;/* ----------------------------------------------------------------------------- FILE LOCAL PROTOTYPES------------------------------------------------------------------------------*//** HISR for Keypad driver */void Keyp_HisrHandler(void);/** detect key type */UINT8 Keyp_GetKeyType(void);/** Keypad state machine */void Keyp_HandleKey(UINT8 u8KeyType);/** Function for unexpected key state */void Keyp_RescueKeyRelease(void);/** Update scancode history variables */void Keyp_UpdateHistory(void);/** Write key into Key struct ans save key into buffer */void Keyp_WriteAndSaveKey1(UINT8 u8Type, UINT32 u32Scan);void Keyp_WriteAndSaveKey2(UINT8 u8Type, UINT32 u32Scan); /** Keypad buffer: write new key */void Keyp_WriteNewKey(UINT8 u8Type, UINT32 u32Scan);/** Keypad buffer: write key release offset */void Keyp_WriteReleaseKey(UINT8 u8Type, UINT32 u32Scan);/** Convert a scancode into a keycode */unsigned char Keyp_LookupCharacter(UINT8 u8Type, UINT32 u32_ScanCode );/** Switch between single key and double key mode */void Keyp_SwitchSingleKeyMode(void);void Keyp_SwitchDoubleKeyMode(void);/* ----------------------------------------------------------------------------- IMPLEMENTATION SECTION EXPORTED FUNCTIONS------------------------------------------------------------------------------*//*-----------------------------------------------------------------------*//** You can find the interface description in add_keyp.h.*//*----------------------------------------------------------------------- */void Keyp_0Init(void){ void (*pKeypadHisrHandler) (void); ///< Pointer to HISR//---- init pointer to keypad HISR _---------------------------------------- pKeypadHisrHandler = Keyp_HisrHandler; // init HISR pointer//---- init peripheral driver ---------------------------------------------- PddKpd_Init(pKeypadHisrHandler); // init PerDD keypad driver part//---- init global variables ----------------------------------------------- // mg_ucWriteOffset = mg_ucReadOffset = 0; // init buffer write and read offset mg_u8KeyState = eIdle; // init state machine// Keyp_SwitchSingleKeyMode(); // default Keypad Mode = Single Key detection Keyp_SwitchDoubleKeyMode(); // default Keypad Mode = double key detection mg_u32CurrentKenum1 = mg_u32OldKenum1 = NO_KEY_SCANCODE;// init scancode history mg_u32CurrentKenum3 = mg_u32OldKenum3 = NO_KEY_SCANCODE;// init scancode history return;}/*-----------------------------------------------------------------------*//** You can find the interface description in add_keyp.h.*//*----------------------------------------------------------------------- */void Keyp_0Exit(void){ PddKpd_Deact(); // deactivation for peripheral device driver return;}/*-----------------------------------------------------------------------*//** You can find the interface description in add_keyp.h.*//*----------------------------------------------------------------------- */BIT Keyp_StatusEndKey(void){ UINT32 u32scancode; BIT detection; u32scancode = PddKpd_ReadEndKey(); // read scancode for special keys only // because only the End-Key is expected detection = 0; // reset value: no End-Key detected if(u32scancode == 0x0000A001) { // End-Key detected detection = 1; // End-Key is detected return(detection); } else { // No End-Key deteceted detection = 0; // no End-Key is detected return(detection); }}/* ----------------------------------------------------------------------------- IMPLEMENTATION SECTION LOCAL FUNCTIONS------------------------------------------------------------------------------*//*-----------------------------------------------------------------------*//** Switch Keypad mode to single key detection. \param none
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -