📄 kpd_scan_functions.c
字号:
KPD_DETECTION_ENABLED, /* timeout long key */
KPD_DETECTION_DISABLED); /* Repeat key enable */
kpd_set_debouncing_time(KPD_DEBOUNCING_TIME);
/* Clear old pending interrupts */
*(volatile UINT16*) KBR_CLR_INTERRUPT_STATUS_REG |= 0xFF;
/* Set default timer values */
*(volatile UINT16*) KBR_LONG_KEY_TIME = KPD_DEFAULT_LONG_TIME;
*(volatile UINT16*) KBR_TIME_OUT = KPD_DEFAULT_TIME_OUT_TIME;
#if (KEYPAD_RF_ISSUE_SW_WORKAROUND == 1 || KEYPAD_RF_ISSUE_SW_WORKAROUND == 2)
*(volatile UINT16*) KBR_FORCE_KBC = 0x01;
#endif
/** Software decoding
*/
#elif (KPD_DECODING_MODE == SOFTWARE_MODE_ENABLE)
/* Init control register ; hardware decoding */
kpd_init_ctrl_reg(1, HARDWARE_DECODING, KPD_CLOCK_DIVIDER,
KPD_DETECTION_DISABLED, KPD_DETECTION_DISABLED,
KPD_DETECTION_DISABLED, KPD_DETECTION_DISABLED);
/* Debouncing time = 64ms */
kpd_set_debouncing_time(KPD_DEBOUNCING_TIME);
/* Activate all outputs */
*(volatile UINT16*) KP_COL_OUT = KP_ALL_ON;
#endif /* KPD_HW_RESOLUTION */
// Bgn >>> Deleted by LI Xiaohan 04/08/09
// Kpd should be unmasked (here) before the kpd task is
// created and should be masked after the task is created.
// To fix the kpd (except PWR) lost issue after switching on.
/* Unmask keypad interrupt */
//IQ_Unmask (C_INTH_KEYBOARD_IT);
//F_INTH_ENABLE_ONE_IT(C_INTH_KEYBOARD_IT);
#else /* Other chipsets */
/* Activate all outputs */
*(volatile UINT16*) KP_COL_OUT = KP_ALL_ON;
/* Unmask keypad interrupt */
#if ((BOARD == 8) || (BOARD == 9) || (BOARD == 40) || (BOARD == 41))
AI_MaskIT(ARMIO_MASKIT_KBD);
#else
IQ_Mask(IQ_ARMIO);
#endif
#endif /* (CHIPSET == 12) */
}
/**
* function: kpd_key_handler
*/
void kpd_key_handler(void)
{
/* If keypad is not started, return immediately */
if ( (kpd_env_ctrl_blk == 0) || (kpd_env_ctrl_blk->swe_is_initialized == FALSE) )
{
kpd_acknowledge_key_pressed();
}
else
{
/* Mask keypad interrupt until key is released */
#if ((BOARD == 8) || (BOARD == 9) || (BOARD == 40) || (BOARD == 41))
AI_MaskIT (ARMIO_MASKIT_KBD);
#elif ((CHIPSET == 12) || (CHIPSET == 15))
F_INTH_DISABLE_ONE_IT(C_INTH_KEYBOARD_IT);
#else
IQ_Mask(IQ_ARMIO);
#endif
/* Activate HISR to process the key event */
NU_Activate_HISR(&hisr_infos.hisr);
}
}
/**
* function: kpd_acknowledge_key_pressed
*/
void kpd_acknowledge_key_pressed(void)
{
/* Unmask keypad interrupt */
#if ((BOARD == 8) || (BOARD == 9) || (BOARD == 40) || (BOARD == 41))
AI_UnmaskIT (ARMIO_MASKIT_KBD);
#elif ((CHIPSET == 12) || (CHIPSET == 15))
F_INTH_ENABLE_ONE_IT(C_INTH_KEYBOARD_IT);
#else
IQ_Unmask (IQ_ARMIO);
#endif
}
/*
* delay
*
* Wait a while to let bus settle
* Magic value found by trial and error
*
*/
static void delay(void)
{
volatile int i;
for (i=0;i<10;i++) ;
}
/**
* function: kpd_scan_keypad
*/
T_KPD_PHYSICAL_KEY_ID kpd_scan_keypad(void)
{
int row, col;
volatile UINT16 rows;
/* Activate all columns to find if any row is active */
*(volatile UINT16*) KP_COL_OUT = KP_ALL_ON;
delay();
rows = (*(volatile UINT16*) KP_ROW_IN) & 0x1F;
if (rows == KP_ALL_OFF)
return KPD_PKEY_NULL;
/* Deactivate all columns */
*(volatile UINT16*) KP_COL_OUT = KP_ALL_OFF;
/* Activate 1 column at a time */
for (col = 0; col < KP_COLS; col++)
{
*(volatile UINT16*) KP_COL_OUT = (KP_ACTIVATE(col));
delay();
/* Find which row is active */
rows = (*(volatile UINT16*) KP_ROW_IN) & 0x1F;
if (rows != KP_ALL_OFF)
{
for (row = 0; row < KP_ROWS; row++)
{
/* first active row */
if ( KP_IS_ACTIVE(rows,row))
{
/* Reactivate all columns */
*(volatile UINT16*) KP_COL_OUT = KP_ALL_ON;
/* DO NOT remove this comment. It allows to simply define the link physical layout
and physical key Id (for a new keypad) */
//KPD_SEND_TRACE_PARAM("KPD: Keypad layout check ", keypad_layout[row][col], RV_TRACE_LEVEL_DEBUG_HIGH);
return keypad_layout[row][col];
}
}
}
}
/* No row was active - Reactivate all columns and return */
*(volatile UINT16*) KP_COL_OUT = KP_ALL_ON;
return KPD_PKEY_NULL;
}
#if ((CHIPSET == 12) || (CHIPSET == 15))
/**
* function: kpd_map_reg_on_layout
*/
T_KPD_PHYSICAL_KEY_ID kpd_map_reg_on_layout(UINT8 key)
{
UINT8 row,col;
row = key / MAX_COL;
col = key % MAX_COL;
return keypad_layout[row][col];
}
#if (KEYPAD_RF_ISSUE_SW_WORKAROUND == 1 || KEYPAD_RF_ISSUE_SW_WORKAROUND == 2)
typedef enum
{
KPD_MODIFY_NONE,
KPD_MODIFY_DEBOUNCE_REG,
KPD_MODIFY_PTV
}KPD_MODIFY_MODE;
#endif
#if (KEYPAD_RF_ISSUE_SW_WORKAROUND == 1 )
KPD_MODIFY_MODE previous_mode;
UINT32 previous_correction_ratio;
/* Modify the KPD timer values */
void kpd_timer_modify(KPD_CORRECTION_RATIO ratio,UINT32 frameNumber)
{
UINT32 debounce_time, long_key_time, timeout_time, temp_count, local_ratio;
INT32 ptv_value;
UINT16 keypad_state;
keypad_state = ((*(volatile UINT16*) KBR_STATE_MACHINE_STATUS) & 0x0f);
debounce_time = (*(volatile UINT16*) KBR_DEBOUNCING_TIME) & 0x3f;
local_ratio = KPD_DEBOUNCING_TIME / debounce_time;
if( keypad_state == 2 || keypad_state == 3 || keypad_state == 4)
{
ptv_value = KPD_CLOCK_DIVIDER;
if( ratio > 1)
{
if( ratio % 2)
{
ratio += 1;
}
if( !ratio )
ratio = 2;
for(temp_count = 0; ratio > 1 && temp_count < 7; temp_count++)
{
ratio /= 2;
}
ptv_value -= temp_count;
}
if( local_ratio > 1)
{
if( ratio % 2)
{
ratio += 1;
}
if( !ratio )
ratio = 2;
for(temp_count = 0; ratio > 1 && temp_count < 7; temp_count++)
{
ratio /= 2;
}
ptv_value += temp_count;
}
if( ptv_value < 0)
ptv_value = 0;
/* Change the PTV value */
SetGroupBits16(*(volatile unsigned short *)(KBR_CTRL_REG), 2, 3, ptv_value);
}
else
{
debounce_time = ((*(volatile UINT16*) KBR_DEBOUNCING_TIME) & 0x3f) * local_ratio;
long_key_time = ((*(volatile UINT16*)KBR_LONG_KEY_TIME) & 0xfff) * local_ratio;
timeout_time = (*(volatile UINT16*) KBR_TIME_OUT) * local_ratio;
//begin: deleted by caisheng 20060822 for no modify to timer
//kpd_env_ctrl_blk->long_time *= local_ratio;
//kpd_env_ctrl_blk->repeat_time *= local_ratio;
//end by caisheng
ptv_value = ((*(volatile UINT16*) KBR_CTRL_REG) & 0x1c) >> 2;
if( ptv_value != KPD_CLOCK_DIVIDER)
{
/* Change the PTV value */
SetGroupBits16(*(volatile unsigned short *)(KBR_CTRL_REG), 2, 3, KPD_CLOCK_DIVIDER);
}
if( ratio > 0 )
{
(*(volatile UINT16*) KBR_DEBOUNCING_TIME) = debounce_time / ratio;
(*(volatile UINT16*) KBR_LONG_KEY_TIME) = long_key_time / ratio;
(*(volatile UINT16*)KBR_TIME_OUT) = timeout_time / ratio;
//begin: deleted by caisheng 20060822 for no modify to timer
//kpd_env_ctrl_blk->long_time /= ratio;
//kpd_env_ctrl_blk->repeat_time /= ratio;
//end by caisheng
}
}
}
#endif
#if (KEYPAD_RF_ISSUE_SW_WORKAROUND == 2)
#define FRAME_NUMBER_MAX 42432
KPD_CORRECTION_RATIO previousRatio = 0;
UINT32 TimeCorrection = 0;
UINT32 KeyPressFrameNumber = FRAME_NUMBER_MAX;
#endif
#if (KEYPAD_RF_ISSUE_SW_WORKAROUND == 1 || KEYPAD_RF_ISSUE_SW_WORKAROUND == 2)
void kpd_state_probe(UINT32 frameNumber)
{
#if (KEYPAD_RF_ISSUE_SW_WORKAROUND == 2)
UINT16 keypad_state;
keypad_state = ((*(volatile UINT16*) KBR_STATE_MACHINE_STATUS) & 0x0f);
if((keypad_state == 2 || keypad_state == 3 || keypad_state == 4) && (KeyPressFrameNumber == FRAME_NUMBER_MAX))
{
KeyPressFrameNumber = frameNumber;
}
else if (TimeCorrection && previousRatio)
{
(*(volatile UINT16*) KBR_DEBOUNCING_TIME) += TimeCorrection / previousRatio;
KeyPressFrameNumber = FRAME_NUMBER_MAX ;
//kpd_timer_modify( globalRatio, frameNumber);
}
else
KeyPressFrameNumber = FRAME_NUMBER_MAX ;
#endif
}
#endif
#if (KEYPAD_RF_ISSUE_SW_WORKAROUND == 2)
void kpd_timer_modify(KPD_CORRECTION_RATIO ratio, UINT32 frameNumber)
{
UINT16 keypad_state, timeExpired;
UINT32 debounce_time, long_key_time, timeout_time;
keypad_state = ((*(volatile UINT16*) KBR_STATE_MACHINE_STATUS) & 0x0f);
if(keypad_state == 2 || keypad_state == 3 || keypad_state == 4)
{
debounce_time = ((*(volatile UINT16*) KBR_DEBOUNCING_TIME) & 0x3f) ;
long_key_time = ((*(volatile UINT16*)KBR_LONG_KEY_TIME) & 0xfff) ;
timeout_time = (*(volatile UINT16*) KBR_TIME_OUT);
if( TimeCorrection && previousRatio )
{
debounce_time += TimeCorrection / previousRatio;
}
if( previousRatio )
{
debounce_time *= previousRatio;
long_key_time *= previousRatio;
timeout_time *= previousRatio;
kpd_env_ctrl_blk->long_time *= previousRatio;
kpd_env_ctrl_blk->repeat_time *= previousRatio;
}
if( frameNumber == FRAME_NUMBER_MAX )
timeExpired = 0;
else if (frameNumber < KeyPressFrameNumber)
{
timeExpired = ((FRAME_NUMBER_MAX - KeyPressFrameNumber) + frameNumber) * 5 + 2;
}
else
timeExpired = (frameNumber - KeyPressFrameNumber) * 5 + 2;
if( ratio > 0 )
{
TimeCorrection = timeExpired;
(*(volatile UINT16*) KBR_DEBOUNCING_TIME) = (KPD_DEBOUNCING_TIME - timeExpired) / ratio;
(*(volatile UINT16*) KBR_LONG_KEY_TIME) = long_key_time / ratio;
(*(volatile UINT16*)KBR_TIME_OUT) = timeout_time / ratio;
kpd_env_ctrl_blk->long_time /= ratio;
kpd_env_ctrl_blk->repeat_time /= ratio;
previousRatio = ratio;
}
}
else
{
debounce_time = ((*(volatile UINT16*) KBR_DEBOUNCING_TIME) & 0x3f) ;
long_key_time = ((*(volatile UINT16*)KBR_LONG_KEY_TIME) & 0xfff) ;
timeout_time = (*(volatile UINT16*) KBR_TIME_OUT);
KeyPressFrameNumber = FRAME_NUMBER_MAX;
if( TimeCorrection && previousRatio)
{
debounce_time += TimeCorrection / previousRatio;
}
if( previousRatio )
{
debounce_time *= previousRatio;
long_key_time *= previousRatio;
timeout_time *= previousRatio;
kpd_env_ctrl_blk->long_time *= previousRatio;
kpd_env_ctrl_blk->repeat_time *= previousRatio;
}
if( ratio > 0 )
{
(*(volatile UINT16*) KBR_DEBOUNCING_TIME) = debounce_time / ratio;
(*(volatile UINT16*) KBR_LONG_KEY_TIME) = long_key_time / ratio;
(*(volatile UINT16*)KBR_TIME_OUT) = timeout_time / ratio;
kpd_env_ctrl_blk->long_time /= ratio;
kpd_env_ctrl_blk->repeat_time /= ratio;
previousRatio = ratio;
TimeCorrection = 0;
}
}
}
#endif
#endif /* CHIPSET == 12 */
#if ( LEN_PDT_ID==2)
/*****************************************************
Copyright (C) 2006 by Renergy. All rights reserved.
Contains confidential proprietary information of horace.
Reverse engineering is prohibited.
The copyright notice does not imply publication.
Project Name: peter2
File Name :
Module :
Description :
Return:
History:
Name Date Version Note
------- --------- -------- -----------
horace 2006/09/08 Initial version
******************************************************/
void bios_slip_send_message(void)
{
T_RVF_MB_STATUS mb_status;
T_KPD_KEY_PRESSED_MSG* msg_slip_pressed;
//Reserve memory for message
mb_status = rvf_get_buf (kpd_env_ctrl_blk->prim_id, sizeof(T_KPD_KEY_PRESSED_MSG), (void **) &msg_slip_pressed);
if (mb_status == RVF_GREEN) // Memory allocation success
{
//Fill the message
msg_slip_pressed->hdr.msg_id = KPD_PROCESS_SLIP_KEY_MSG;
//Send message to the keypad task
rvf_send_msg(kpd_env_ctrl_blk->addr_id, msg_slip_pressed);
}
else
{
BIOS_TRACE_DEBUG("slip sending message fail----not enough memory!!!!!");
if (mb_status == RVF_YELLOW)
rvf_free_buf(msg_slip_pressed);
}
}
#endif
/*@}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -