diff --git a/model/input/driver/hdf_hid_adapter.c b/model/input/driver/hdf_hid_adapter.c index ca3d4e8e8cc3796d55f8fcd09943d1799d1ec8fc..1ab568243f094cd993b56a0bfe06fdfb05d1d81e 100644 --- a/model/input/driver/hdf_hid_adapter.c +++ b/model/input/driver/hdf_hid_adapter.c @@ -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; } diff --git a/model/input/driver/hdf_hid_adapter.h b/model/input/driver/hdf_hid_adapter.h index dbf393b0525edeb392aeeccfc55b8f93f1694d4d..83efe6140afc619894f529c24ee6ec20b34551ff 100644 --- a/model/input/driver/hdf_hid_adapter.h +++ b/model/input/driver/hdf_hid_adapter.h @@ -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); diff --git a/model/input/driver/hdf_input_device_manager.c b/model/input/driver/hdf_input_device_manager.c index c3e762c5f6a0f498c74c291ba10fd2098823e596..9be0cce56e19eaeb8409ae4bc6f32f66e940eada 100644 --- a/model/input/driver/hdf_input_device_manager.c +++ b/model/input/driver/hdf_input_device_manager.c @@ -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; diff --git a/model/input/driver/hdf_input_device_manager.h b/model/input/driver/hdf_input_device_manager.h index be36197abe59534535b80fa23856389268af5954..98d247d88b91cef0c54e753daf958bfe448e790e 100644 --- a/model/input/driver/hdf_input_device_manager.h +++ b/model/input/driver/hdf_input_device_manager.h @@ -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 \ No newline at end of file