📄 kpddrv.c
字号:
/****************************************************************************
** Notice: Copyright (c) 1998 LSI Logic Corporation - All Rights Reserved
**
** File Name: KPDDRV.C
**
** $Revision: \main\20010426_1.4_integration_branch\4 $
** $Date: Wed Aug 1 07:32:38 2001 $
**
** Description:
** Keypad driver API and support functions. The keypad driver generates
** key press and key release events as per OpenTV.
**
****************************************************************************/
#include <gendefs.h> /* Generic Definitions system wide */
#include <keyirdef.h> /* Common Keypad & IR definitions for buttons */
#include <kpddrv.h> /* Macros, protos for keypad driver */
#include <osp.h> /* OSP Prototypes, and macros */
#include <sgo.h> /* EVB specific GPIO APIs */
/***************************************************************************
** Generic Keypad Access Register. The keypad is mapped through GPIOs.
****************************************************************************/
#define KPD_REGISTER (*((volatile UINT8 *) 0xB8660000))
/****************************************************************************
** Value (ms) for KPD SCAN
****************************************************************************/
#define KPD_POLL_INTERVAL (20)
/****************************************************************************
** Value for KPD Qusue size
****************************************************************************/
#define KPD_QUEUE_SIZE (16)
/****************************************************************************
** Value for KPD Task stack size
****************************************************************************/
#define KPD_TASK_STACK_SIZE (0x2000)
/****************************************************************************
** Local Variables
****************************************************************************/
/* Local variables for key sent,counter for LED, and KeypadEnabled */
static UINT8 LastKeySent = 0;
static UINT8 KeypadEnabled;
/****************************************************************************
** Local Function Declarations
****************************************************************************/
static void KPDTask(void);
static void (*KeySendCallback)(UINT32, UINT32, UINT32);
static INT32 CallbackAssigned = FALSE;
/* KPDDisable() is not called by anyone, keep it for future use */
/****************************************************************************
** Function KPDDisable(): Disable the keypad interface.
**
** Inputs: None.
**
** Outputs: None.
**
** Returns: None.
****************************************************************************/
void KPDDisable(void)
{
KeypadEnabled = FALSE;
}
/* KPDEnable() is not called by anyone, keep it for future use */
/****************************************************************************
** Function KPDEnable(): Enable the keypad interface.
**
** Inputs: None.
**
** Outputs: None.
**
** Returns: None.
****************************************************************************/
void KPDEnable(void)
{
KeypadEnabled = TRUE;
}
/****************************************************************************
** Function KPDRegisterCallback(): This function is used to register
** the keysend callback with the keypad driver. The function is also used
** to unregister by passing a NULL pointer parameter.
**
** Inputs: callbackFunction
**
** Outputs: none.
**
** Returns: SUCCESS.
****************************************************************************/
void KPDRegisterKeySendCallback(void (*callbackFunction)(UINT32, UINT32, UINT32))
{
KeySendCallback = callbackFunction;
CallbackAssigned = TRUE;
}
/****************************************************************************
** Function KPDInitialize(): Initialize the keypad driver inclduing Keypad
** Task, Keypad scan task, and check for keypad type
**
** Inputs: taskPriority, Keypad task Priority.
**
** Outputs: None.
**
** Returns: SUCCESS/FAILURE.
****************************************************************************/
INT32 KPDInitialize(INT32 taskPriority)
{
UINT32 kpdTaskID;
INT32 returnCode;
CallbackAssigned = FALSE;
KPDEnable();
returnCode = OSPTaskCreate("KPDT", KPD_TASK_STACK_SIZE, KPDTask,
taskPriority, 0, 0, &kpdTaskID);
return (returnCode);
}
/****************************************************************************
** Function KPDTask(): Control loop for the Keypad task. This task
** flash LED, poll the keypad status, decode Key ID, software debouncing
** and involves the registered callback. This task also generates the
** PRESS and RELEASE events for OPEN TV requirement.
**
** Inputs: None.
**
** Outputs: None.
**
** Returns: Never. This is a task.
****************************************************************************/
static void KPDTask(void)
{
UINT8 keyID;
while(TRUE)
{
OSPTaskTemporarySleep(KPD_POLL_INTERVAL); /* sleep for a while */
if(KeypadEnabled)
{
keyID = SGOReadKeypad();
if(keyID) /* Key press detected */
{
if(keyID != LastKeySent) /* send Key ID with key press */
{
if (CallbackAssigned == TRUE)
{
KeySendCallback(KEY_PRESS, SOURCE_KEYPAD, keyID);
}
}
} /* end of if(keyBits) */
else /* Key detected as release or not pressed */
{
if(keyID != LastKeySent) /* send Key ID with key released */
{
keyID = 0;
if (CallbackAssigned == TRUE)
{
KeySendCallback(KEY_RELEASE, SOURCE_KEYPAD, LastKeySent);
}
}
} /* end of else */
LastKeySent = keyID;
} /* end of if(KeypadEnabled) */
} /* end while (TRUE) */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -