!229 add trackball

Merge pull request !229 from 黄凯/master
This commit is contained in:
openharmony_ci
2021-09-07 07:23:31 +00:00
committed by Gitee
4 changed files with 56 additions and 18 deletions
+31 -14
View File
@@ -89,7 +89,7 @@ void SendInfoToHdf(HidInfo *info)
}
}
static void FreeCachedInfo()
static void FreeCachedInfo(void)
{
int32_t id = 0;
while (id < MAX_INPUT_DEV_NUM) {
@@ -101,14 +101,24 @@ static void FreeCachedInfo()
}
}
static void SetInputDevAbility(InputDevice *inputDev)
static int32_t SetInputDevAbsAttr(InputDevice *inputDev, HidInfo *info)
{
HidInfo *info = NULL;
int32_t id = 0;
uint32_t len;
int32_t ret;
for (int i = 0; i < BITS_TO_LONG(ABS_CNT); i++) {
if (inputDev->abilitySet.absCode[i] != 0) {
ret = memcpy_s(inputDev->attrSet.axisInfo, sizeof(AbsAttr) * ABS_CNT,
info->axisInfo, sizeof(AbsAttr) * ABS_CNT);
return ret;
}
}
return HDF_SUCCESS;
}
static int32_t GetInfoFromCache(InputDevice *inputDev, HidInfo *info)
{
int32_t id = 0;
while (id < MAX_INPUT_DEV_NUM) {
if(g_cachedInfo[id] != NULL && !strcmp(inputDev->devName, g_cachedInfo[id]->devName)) {
if (g_cachedInfo[id] != NULL && !strcmp(inputDev->devName, g_cachedInfo[id]->devName)) {
info = g_cachedInfo[id];
break;
}
@@ -116,8 +126,19 @@ static void SetInputDevAbility(InputDevice *inputDev)
}
if (id == MAX_INPUT_DEV_NUM || info == NULL) {
HDF_LOGE("%s: match cached info failed", __func__);
return;
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static void SetInputDevAbility(InputDevice *inputDev)
{
HidInfo *info = NULL;
uint32_t len;
int32_t ret;
ret = GetInfoFromCache(inputDev, info);
MEMCPY_CHECK_RETURN(ret);
len = sizeof(unsigned long);
ret = memcpy_s(inputDev->abilitySet.devProp, len * BITS_TO_LONG(INPUT_PROP_CNT),
info->devProp, len * BITS_TO_LONG(INPUT_PROP_CNT));
@@ -149,12 +170,12 @@ static void SetInputDevAbility(InputDevice *inputDev)
ret = memcpy_s(inputDev->abilitySet.switchCode, len * BITS_TO_LONG(SW_CNT),
info->switchCode, len * BITS_TO_LONG(SW_CNT));
MEMCPY_CHECK_RETURN(ret);
ret = SetInputDevAbsAttr(inputDev, info);
MEMCPY_CHECK_RETURN(ret);
inputDev->attrSet.id.busType = info->bustype;
inputDev->attrSet.id.vendor = info->vendor;
inputDev->attrSet.id.product = info->product;
inputDev->attrSet.id.version = info->version;
FreeCachedInfo();
}
@@ -343,9 +364,8 @@ static int32_t HidGetDeviceAttr(InputDevice *inputDev, struct HdfSBuf *reply)
return HDF_FAILURE;
}
HDF_LOGE("%s: enter", __func__);
ret = strncpy_s(inputDev->attrSet.devName, DEV_NAME_LEN, inputDev->devName, strlen(inputDev->devName));
if (ret) {
if (ret != 0) {
HDF_LOGE("%s: copy name from inputDev failed, ret = %d", __func__, ret);
return HDF_FAILURE;
}
@@ -355,7 +375,6 @@ static int32_t HidGetDeviceAttr(InputDevice *inputDev, struct HdfSBuf *reply)
return HDF_FAILURE;
}
HDF_LOGI("%s: get dev attr succ", __func__);
return HDF_SUCCESS;
}
@@ -364,14 +383,12 @@ static int32_t HidGetDeviceAbility(InputDevice *inputDev, struct HdfSBuf *reply)
if (inputDev == NULL) {
return HDF_FAILURE;
}
HDF_LOGE("%s: enter", __func__);
if (!HdfSbufWriteBuffer(reply, &inputDev->abilitySet, sizeof(DevAbility))) {
HDF_LOGE("%s: sbuf write dev ability failed", __func__);
return HDF_FAILURE;
}
HDF_LOGI("%s: get dev ability succ", __func__);
return HDF_SUCCESS;
}
+12 -1
View File
@@ -47,6 +47,15 @@
#define FF_MAX 0x7f
#define HDF_FF_CNT (FF_MAX + 1)
typedef struct {
int32_t axis;
int32_t min;
int32_t max;
int32_t fuzz;
int32_t flat;
int32_t range;
} AbsAttr;
typedef struct HidInformation {
uint32_t devType;
const char *devName;
@@ -61,6 +70,7 @@ typedef struct HidInformation {
unsigned long soundCode[BITS_TO_LONG(HDF_SND_CNT)];
unsigned long forceCode[BITS_TO_LONG(HDF_FF_CNT)];
unsigned long switchCode[BITS_TO_LONG(HDF_SW_CNT)];
AbsAttr axisInfo[HDF_ABS_CNT];
uint16_t bustype;
uint16_t vendor;
@@ -78,11 +88,12 @@ enum HidType {
HID_TYPE_MOUSE, /* Mouse */
HID_TYPE_KEYBOARD, /* Keyboard */
HID_TYPE_ROCKER, /* ROCKER */
HID_TYPE_TRACKBALL, /* TRACKBALL */
HID_TYPE_UNKNOWN, /* Unknown input device type */
};
void SendInfoToHdf(HidInfo *info);
void* HidRegisterHdfInputDev(HidInfo *dev);
void* HidRegisterHdfInputDev(HidInfo *info);
void HidUnregisterHdfInputDev(const void *inputDev);
void HidReportEvent(const void *inputDev, uint32_t type, uint32_t code, int32_t value);
+11 -2
View File
@@ -197,6 +197,7 @@ EXIT:
#define DEFAULT_CROWN_BUF_PKG_NUM 20
#define DEFAULT_ENCODER_BUF_PKG_NUM 20
#define DEFAULT_ROCKER_BUF_PKG_NUM 40
#define DEFAULT_TRACKBALL_BUF_PKG_NUM 30
static int32_t AllocPackageBuffer(InputDevice *inputDev)
{
@@ -223,6 +224,9 @@ static int32_t AllocPackageBuffer(InputDevice *inputDev)
case INDEV_TYPE_ROCKER:
pkgNum = DEFAULT_ROCKER_BUF_PKG_NUM;
break;
case INDEV_TYPE_TRACKBALL:
pkgNum = DEFAULT_TRACKBALL_BUF_PKG_NUM;
break;
default:
HDF_LOGE("%s: devType not exist", __func__);
return HDF_FAILURE;
@@ -246,8 +250,13 @@ static uint32_t AllocDeviceID(InputDevice *inputDev)
InputDevice *tmpDev = g_inputManager->inputDevList;
uint32_t idList[MAX_INPUT_DEV_NUM + 1];
uint32_t id;
(void)memset_s(idList, (MAX_INPUT_DEV_NUM + 1) * sizeof(uint32_t), 0,
(MAX_INPUT_DEV_NUM + 1) * sizeof(uint32_t));
int32_t ret;
ret = memset_s(idList, (MAX_INPUT_DEV_NUM + 1) * sizeof(uint32_t), 0,
(MAX_INPUT_DEV_NUM + 1) * sizeof(uint32_t));
if (ret != 0) {
HDF_LOGE("%s: memset_s is failed", __func__);
return HDF_FAILURE;
}
while (tmpDev != NULL) {
if (idList[tmpDev->devId] == 0) {
idList[tmpDev->devId] = FILLER_FLAG;
@@ -134,6 +134,7 @@ enum InputDevType {
INDEV_TYPE_MOUSE, /* Mouse */
INDEV_TYPE_KEYBOARD, /* Keyboard */
INDEV_TYPE_ROCKER, /* ROCKER */
INDEV_TYPE_TRACKBALL, /* TRACKBALL */
INDEV_TYPE_UNKNOWN, /* Unknown input device type */
};
@@ -165,6 +166,6 @@ enum TouchIoctlCmd {
};
InputManager* GetInputManager(void);
int32_t RegisterInputDevice(InputDevice *device);
void UnregisterInputDevice(InputDevice *device);
void UnregisterInputDevice(InputDevice *inputDev);
#endif