📄 keypad_plat.c
字号:
/*IN5*/
/*OUT0 */XLLP_KP_SC_N_UP,
/*OUT1 */XLLP_KP_SC_N_DOWN,
/*OUT2 */XLLP_KP_SC_N_LEFT,
/*OUT3 */XLLP_KP_SC_N_RIGHT,
/*OUT4 */XLLP_KP_SC_N_ACTION,
/*6 Direct Keys*/
/*DKEY0 */XLLP_KP_SC_SCROLL_UP,
/*DKEY1 */XLLP_KP_SC_SCROLL_DOWN,
/*DKEY2 */XLLP_KP_SC_INVALID_KEY,
/*DKEY3 */XLLP_KP_SC_INVALID_KEY,
/*DKEY4 */XLLP_KP_SC_INVALID_KEY
}; /*xllpKpScanCodeLutLower*/
#define XLLP_KEYPAD_COLS_NUM 5
#define XLLP_KEYPAD_ROWS_NUM 6
/*-----------------------------------------------------------------------
Function: xllp_keypad_config_mfp
Purpose: This function configures the MFP for keypad
Returns: XLLPSTATUS_T
Type No: I/F flat 1
--------------------------------------------------------------------------*/
XLLP_STATUS_T xllp_keypad_config_mfp(
P_XLLP_VUINT32_T pMfpRegBase,
P_XLLP_MFP_RM_DB_ID_T pMfpRmDb)
{
XLLP_STATUS_T retval = XLLP_STATUS_SUCCESS;
XLLP_VUINT32_T mfpLocker;
retval = XllpMfpResourceManager_List(
pMfpRmDb,
xllp_keypad_mfp_list,
XLLP_MFP_RM_ID_XLLP_KEYPAD ,
XLLP_SET);
if ( XLLP_STATUS_SUCCESS != retval) {
return retval ;
}
/*
Lock MFPR block until finished with all MFPRs.
Don't forget to unlock for early returns, too.*/
//If need be use proper serialization object for MFPR registers
/*Assign the Alternate Functions and Drive Strengths for each keypad MFP.*/
retval = XllpMfpSetAfDs_List(
pMfpRegBase,
xllp_keypad_mfp_list,
xllp_keypad_af_list,
xllp_keypad_ds_list);
if ( XLLP_STATUS_SUCCESS != retval) {
//release serialization object
return retval ;
}
/*
Configure the pin output levels for low power modes.
The pulled level settings also apply to functional mode (non-LPM) if
activated for that use - but they are not so activated for the
keypad.
*/
/* retval = XllpMfpConfigureLpmOutputLevel_List (
pMfpRegBase,
xllp_keypad_mfp_list,
xllp_keypad_lpm_output_list);
if ( XLLP_STATUS_SUCCESS != retval) {
//Release serialization object
return retval ;
}*/
/*
Configure the LPM wake up edge triggers for each interesting keypad MFP.
This does not enable or disable the edge triggering, which must be done
elsewhere.
*/
retval = XllpMfpConfigureWakeup_List (
pMfpRegBase,
xllp_keypad_wakeup_pins_candidates_list,
xllp_keypad_configure_wakeup_edges_list);
if ( XLLP_STATUS_SUCCESS != retval) {
//Release serialization object
return retval ;
}
/*
XLLI sets all pins to an activated pulled non-LPM level in order to
establish a low-power default setting. That is helpful if a driver is
not loaded to control some pins, but here we are. So deactivate
that now in order to avoid conflicts with the Keypad Interface device.
*/
/*retval = XllpMfpActivatePullUpDown_List (
pMfpRegBase,
xllp_keypad_mfp_list,
XLLP_OFF);
if ( XLLP_STATUS_SUCCESS != retval) {
//Release serialization object
return retval ;
}*/
/*
Do locking read
Similarly to "Split Transactions", this read guarantees that the writes
to all MFPRs have taken effect in the pins before proceeding.
*/
retval = XllpMfpGetPinConfig (
pMfpRegBase,
xllp_keypad_wakeup_pins_candidates_list[0],
&mfpLocker);
if ( XLLP_STATUS_SUCCESS != retval) {
//Release serialization object
return retval ;
}
//Release serialization object
return XLLP_STATUS_SUCCESS;
}/*end xllp_keypad_config_mfp*/
/*-----------------------------------------------------------------------------------------
Function: XllpKeyPadEnableLpmWakeup
Purpose: This function enables or disables waking up from Low Power Modes based on
the configured MFP edge triggers for the keypad.
XLLP_STATUS_SUCCESS - All parameters were valid.
XLLP_STATUS_WRONG_PARAMETER - Null pointer received or parameter
is out of range.
--------------------------------------------------------------------------------------------*/
XLLP_STATUS_T XllpKeyPadEnableLpmWakeup (
P_XLLP_VUINT32_T pMfpRegBase,
XLLP_CONTROL_T enable)
{
XLLP_STATUS_T retval;
XLLP_VUINT32_T mfpLocker;
retval = XllpMfpEnableWakeup_List (
pMfpRegBase,
xllp_keypad_wakeup_pins_list,
enable);
if ( XLLP_STATUS_SUCCESS != retval) {
return retval ;
}
// Do locking read
// Similarly to "Split Transactions", this read guarantees that the writes
// to all MFPRs have taken effect in the pins before proceeding.
retval = XllpMfpGetPinConfig (
pMfpRegBase,
xllp_keypad_wakeup_pins_list[0],
&mfpLocker);
return(retval);
} // end of XllpKeyPadEnableLpmWakeup ()
/*----------------------------------------------------------------------------
Function: XllpReadScanCode
Purpose:
Returns:
-----------------------------------------------------------------------------*/
XLLP_STATUS_T XllpReadScanCode(
XLLP_KEYPAD_REGS *v_pkeypad_regs,
XLLP_UINT32_T *num_of_keys_pressed,
XLLP_UINT8_T *pui8_data)
{
XLLP_UINT32_T kp_status;
XLLP_UINT8_T keys[35];
XLLP_UINT32_T i;
#ifdef XLLP_DEBUG_PARAM_CHECK
if ( NULL == v_pkeypad_regs||NULL == pui8_data)
return XLLP_STATUS_WRONG_PARAMETER;
#endif
/**
Max 35 key events:
1) 6 * 5 matrix keys
2) 5 direct keys
if one key is pressed, keyIndex[i] is set to 1
**/
memset(keys, NO_KEY, 35*sizeof(XLLP_UINT8_T));
*num_of_keys_pressed=0;
kp_status = v_pkeypad_regs->kpControlReg;
/*
Process matrix first to capture scroll
wheel press rather than interpreting it
as a rotate, which can happen unintentionally.
*/
if(kp_status & MATRIX_INTR_BIT)
{
read_scan_code_automatically(v_pkeypad_regs,num_of_keys_pressed,keys);
if(!num_of_keys_pressed)
{
return(XLLP_STATUS_FAILURE);
}
for (i=0; i<*num_of_keys_pressed; i++)
pui8_data[i] = xllpKpScanCodeLut[keys[i]];
}
else if(kp_status & DIRECT_INTR_BIT )
{
if(XLLP_STATUS_SUCCESS == read_direct_keys(v_pkeypad_regs, keys))
{
*num_of_keys_pressed=1;
pui8_data[0]=keys[0];
}
else
{
*num_of_keys_pressed=0; // return XLLP_STATUS_FAILURE;
}
}
if(!num_of_keys_pressed){
return(XLLP_STATUS_FAILURE);
}
else{
return(XLLP_STATUS_SUCCESS);
}
}/*end function XllpReadScanCode*/
/*------------------------------------------------------------
Function: XllpKeyPadConfigure
Purpose: This function configures the KeyPad Controller on Littleton with the
appropriate settings.
Returns: success/failure.
--------------------------------------------------------------*/
XLLP_STATUS_T XllpKeyPadConfigure (
XLLP_KEYPAD_REGS * pKeyPadRegs,
P_XLLP_VUINT32_T pMfpRegBase,
P_XLLP_MFP_RM_DB_ID_T pMfpRmDb,
XLLP_BOOL_T useDefaultDebounces,
XLLP_UINT8_T matrixDebounceMs,
XLLP_UINT8_T directDebounceMs)
{
XLLP_STATUS_T re;
re = xllp_keypad_config_mfp(pMfpRegBase, pMfpRmDb);
xllp_keypad_config_controller(
pKeyPadRegs,
useDefaultDebounces,
matrixDebounceMs,
directDebounceMs,
XLLP_KEYPAD_ROWS_NUM,
XLLP_KEYPAD_COLS_NUM);
return(re);
}/*end function XllpKeyPadConfigure*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -