You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.8 KiB
95 lines
2.8 KiB
/*
|
|
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2022. All rights reserved.
|
|
* Description: virtualkeypad input gpio power interface
|
|
* Author: App-Dev Group
|
|
* Create: 2020-06-12
|
|
*/
|
|
|
|
#include <string>
|
|
#include "uapi_pdm.h"
|
|
#include "uapi_pmoc.h"
|
|
#include "GpioPowerInterface.h"
|
|
|
|
using namespace android;
|
|
|
|
void GpioPowerInterface::GpioPowerInit()
|
|
{
|
|
keyPars->GetGpioKeyPad(gpioKpd);
|
|
gpioEnable = gpioKpd.bEnable;
|
|
|
|
/* close gpio opt */
|
|
if (gpioEnable == 0) {
|
|
return;
|
|
}
|
|
|
|
if (lsadcEnable == 1) {
|
|
VIRTUALKEY_LOG("Both LSADC and GPIO switches are on, please check the configuration!\n");
|
|
}
|
|
|
|
VIRTUALKEY_LOG("virtualkeypad: ENTER GpioPowerInit");
|
|
if (gpioFlag == TD_FAILURE) {
|
|
int ret = gpioInterface->GpioInit();
|
|
if (ret != TD_SUCCESS) {
|
|
VIRTUALKEY_LOG("GpioInit err, 0x%08x !\n", ret);
|
|
return;
|
|
}
|
|
if (gpioKpd.u8KeyLevelNum > GPIO_MAX_NUM) {
|
|
return;
|
|
}
|
|
for (unsigned int i = 0; i < gpioKpd.u8KeyLevelNum; i++) {
|
|
ret = gpioInterface->GpioSetDirection(gpioKpd.u8GroupNum[i], gpioKpd.u8PinNum[i], TD_TRUE);
|
|
if (ret != TD_SUCCESS) {
|
|
VIRTUALKEY_LOG("GpioSetDirection err, 0x%08x !\n", ret);
|
|
gpioInterface->GpioDeinit();
|
|
return;
|
|
}
|
|
}
|
|
|
|
gpioFlag = TD_SUCCESS; /* SUCESS */
|
|
}
|
|
}
|
|
|
|
void GpioPowerInterface::GpioPowerDeinit()
|
|
{
|
|
/* close gpio opt */
|
|
if (gpioEnable == 0) {
|
|
return;
|
|
}
|
|
|
|
VIRTUALKEY_LOG("virtualkeypad: ENTER GpioPowerDeinit");
|
|
if (gpioFlag == TD_SUCCESS) {
|
|
gpioInterface->GpioDeinit();
|
|
gpioFlag = TD_FAILURE;
|
|
}
|
|
}
|
|
|
|
void GpioPowerInterface::DoGpioPowerOpt() const
|
|
{
|
|
static td_bool curHighVolt[GPIO_MAX_NUM] = {TD_TRUE};
|
|
static td_bool perHighVolt[GPIO_MAX_NUM] = {TD_TRUE};
|
|
static td_u32 killShakeCnt[GPIO_MAX_NUM] = {0};
|
|
if (gpioKpd.u8KeyLevelNum > GPIO_MAX_NUM) {
|
|
return;
|
|
}
|
|
for (int i = 0; i < gpioKpd.u8KeyLevelNum; i++) {
|
|
int ret = gpioInterface->GpioRead(gpioKpd.u8GroupNum[i], gpioKpd.u8PinNum[i], (curHighVolt[i]));
|
|
if (ret != TD_SUCCESS) {
|
|
VIRTUALKEY_LOG("call GpioRead fail , read value error(0x%08x)\n", ret);
|
|
continue;
|
|
}
|
|
|
|
if (perHighVolt[i] == curHighVolt[i]) { /* same opt , do nothing */
|
|
killShakeCnt[i] = 0;
|
|
continue;
|
|
}
|
|
|
|
if ((killShakeCnt[i]++) >= checkCount) {
|
|
/* press_key */
|
|
VIRTUALKEY_LOG("press gpio keycod(%x).\n", gpioKpd.u32KeyCode[i]);
|
|
// 1 trigger button, 0 means not trigger
|
|
keypadInputInterface->WriteEventToDevice(gpioKpd.u32KeyCode[i], curHighVolt[i] ? 0 : 1);
|
|
perHighVolt[i] = curHighVolt[i];
|
|
}
|
|
}
|
|
}
|