⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 keypad.c

📁 IT projecotr reference design.
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************/
/*             TEXAS INSTRUMENTS PROPRIETARY INFORMATION                    */
/*                                                                          */
/*  (c) Copyright, Texas Instruments Incorporated, 2006.                    */
/*      All Rights Reserved.                                                */
/*                                                                          */
/*  Property of Texas Instruments Incorporated. Restricted Rights -         */
/*  Use, duplication, or disclosure is subject to restrictions set          */
/*  forth in TI's program license agreement and associated documentation.   */
/****************************************************************************/

/****************************************************************************/
/* keypad.c                                                                 */
/*                                                                          */
/* Keypad scanner and LED indicator functions.                              */
/****************************************************************************/

#include "common.h"
#include "gpio.h"

#include "gpioFunction.h"
#include "keypad.h"
#include "keycode.h"
#include "guiApp.h"

#include "dbmessage.h"

                        /****************************************************/
                        /* Local constants.                                 */
                        /****************************************************/

#define SETMENU         0x40             /* Menu mode bit in decoding array */
#define SETKPAD         0x00          /* No menu mode bit in decoding array */

                        /****************************************************/
                        /* Key decoder machine states.                      */
                        /****************************************************/

#define STATE_IDLE        0                                         /* idle */
#define STATE_DEBOUNCE    1                     /* debounce a new scan code */
#define STATE_DELAY       2                     /* delay before auto-repeat */
#define STATE_REPEAT      3                                  /* auto-repeat */

                        /****************************************************/
                        /* Keypad GPIO scan bits.                           */
                        /*                                                  */
                        /* GIO_* pin definitions in gpiofunction.h          */
                        /****************************************************/

const static uint08 keyScanVector[] =
{
    GIO_KPAD_POWER,                                /* bit 0x20 in scan code */
    GIO_KPAD_UP   ,                                /* bit 0x10 in scan code */
    GIO_KPAD_DOWN ,                                /* bit 0x08 in scan code */
    GIO_KPAD_LEFT ,                                /* bit 0x04 in scan code */
    GIO_KPAD_RIGHT,                                /* bit 0x02 in scan code */
    GIO_KPAD_SEL                                   /* bit 0x01 in scan code */
};

const static int scancount = sizeof( keyScanVector );


                        /****************************************************/
                        /* Keypad decoder array.                            */
                        /****************************************************/

const static struct keycodestruct
{
    KCODE_ENUM code;                                     /* decoded keycode */
    uint08     scan;               /* IO scan code (bit set if key pressed) */
    BOOL       repflag;                             /* code-can-repeat flag */

}
    keyCode[] =
{
    { KCODE_PAD_MENU     , 0x01, FALSE },   /*  0   0   0   0   0   0   1   */
    { KCODE_PAD_BRIGHT   , 0x02, FALSE },   /*  0   0   0   0   0   1   0   */
    { KCODE_PAD_ZOOM     , 0x04, FALSE },   /*  0   0   0   0   1   0   0   */
    { KCODE_PAD_LEFTRIGHT, 0x06, FALSE },   /*  0   0   0   0   1   1   0   */
    { KCODE_PAD_KEYSTONE , 0x08, FALSE },   /*  0   0   0   1   0   0   0   */
    { KCODE_PAD_SOURCE   , 0x10, FALSE },   /*  0   0   1   0   0   0   0   */
    { KCODE_PAD_UPDOWN   , 0x18, FALSE },   /*  0   0   1   1   0   0   0   */
    { KCODE_PAD_POWER    , 0x20, FALSE },   /*  0   1   0   0   0   0   0   */

    { KCODE_PAD_MM_SELECT, 0x41, FALSE },   /*  1   0   0   0   0   0   1   */
    { KCODE_PAD_MM_RIGHT , 0x42, TRUE  },   /*  1   0   0   0   0   1   0   */
    { KCODE_PAD_MM_LEFT  , 0x44, TRUE  },   /*  1   0   0   0   1   0   0   */
    { KCODE_PAD_LEFTRIGHT, 0x46, FALSE },   /*  1   0   0   0   1   1   0   */
    { KCODE_PAD_MM_DOWN  , 0x48, TRUE  },   /*  1   0   0   1   0   0   0   */
    { KCODE_PAD_MM_UP    , 0x50, TRUE  },   /*  1   0   1   0   0   0   0   */
    { KCODE_PAD_UPDOWN   , 0x58, FALSE },   /*  1   0   1   1   0   0   0   */                 
    { KCODE_PAD_POWER    , 0x60, FALSE },   /*  1   1   0   0   0   0   0   */
};
/*    |                    |     |              |   |   |   |   |   |   |   */
/*    |                    |     |              |   |   |   |   |   |   |   */
/*    |                    |     |              |   |   |   |   |   |   |   */
/*    |                    |     |              |   |   |   |   |   |   |   */
/*                                                                          */
/*    Code                 Scan  Repeat      Menu   Pwr Up  Dwn Lft Rgt Sel */

const static int keycount = sizeof( keyCode ) / sizeof( struct keycodestruct );


                        /****************************************************/
                        /* Key decoder timing.                              */
                        /****************************************************/

#define DEBOUNCECOUNT   2                       /* number of debounce scans */
#define DELAYCOUNT     20                /* number of scans to delay repeat */
#define REPEATCOUNT     2             /* number of scans at which to repeat */

                        /****************************************************/
                        /* Local variables.                                 */
                        /****************************************************/

static int16      state;                     /* scanner state machine state */
static int16      count;                         /* count of scans in state */
static uint08     currentscan;                         /* current scan code */
static KCODE_ENUM savekey;              /* last valid code returned by scan */
static uint08     menubit;                        /* menu/function mode bit */

                        /****************************************************/
                        /* Local functions.                                 */
                        /****************************************************/

static KCODE_ENUM keypad_scan( void );
static BOOL decodeKey( uint08 scancode, KCODE_ENUM *retcode );



/****************************************************************************/
/* Initialize keypad hardware and software interfaces.                      */
/****************************************************************************/

EXEC_CC_ENUM keypad_init( void )
{
                        /****************************************************/
                        /* Configure keypad input pins.                     */
                        /****************************************************/

    GPIO_SetPinConfig( GIO_KPAD_POWER, GIOCFG_INPUT, TRUE,  GIOCFG_OPENDRAIN );
    GPIO_SetPinConfig( GIO_KPAD_UP,    GIOCFG_INPUT, TRUE,  GIOCFG_OPENDRAIN );
    GPIO_SetPinConfig( GIO_KPAD_DOWN,  GIOCFG_INPUT, TRUE,  GIOCFG_OPENDRAIN );
    GPIO_SetPinConfig( GIO_KPAD_LEFT,  GIOCFG_INPUT, TRUE,  GIOCFG_OPENDRAIN );
    GPIO_SetPinConfig( GIO_KPAD_RIGHT, GIOCFG_INPUT, TRUE,  GIOCFG_OPENDRAIN );
    GPIO_SetPinConfig( GIO_KPAD_SEL,   GIOCFG_INPUT, TRUE,  GIOCFG_OPENDRAIN );

                        /****************************************************/
                        /* Configure LED output pins.                       */
                        /*  Power:         On                               */
                        /*  Lamp overheat: Off                              */
                        /*  Proj overheat: Off                              */
                        /****************************************************/

    GPIO_SetPinConfig( GIO_KPAD_LEDPOWER, GIOCFG_OUTPUT, TRUE,  GIOCFG_ACTIVE );
    GPIO_SetPinConfig( GIO_KPAD_LEDLAMP,  GIOCFG_OUTPUT, FALSE, GIOCFG_ACTIVE );
    GPIO_SetPinConfig( GIO_KPAD_LED_HOT,  GIOCFG_OUTPUT, FALSE, GIOCFG_ACTIVE );

                        /****************************************************/
                        /* Initialize key state machine.                    */
                        /****************************************************/

    state       = STATE_IDLE;                /* scanner state machine state */
    currentscan = 0;                                     /* prior scan code */
    menubit     = 0;                                          /* menu state */

    return EXEC_CC_PASS;
}



/****************************************************************************/
/* Set state of keypad LED.                                                 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -