diff --git a/model/input/driver/hdf_hid_adapter.c b/model/input/driver/hdf_hid_adapter.c index 47496b8a6221c40e81e0e866ddaa858f33c7625f..bfd7a771a5234d13f99d40c375a51d3e0f246550 100644 --- a/model/input/driver/hdf_hid_adapter.c +++ b/model/input/driver/hdf_hid_adapter.c @@ -15,7 +15,7 @@ #include "hdf_hid_adapter.h" InputDevice *cachedHid[MAX_INPUT_DEV_NUM]; -HidInfo cachedInfo[MAX_INPUT_DEV_NUM]; +HidInfo *g_cachedInfo[MAX_INPUT_DEV_NUM]; static bool HaveHidCache(void) { @@ -47,7 +47,7 @@ static int cachedPosId(void) { int32_t id = 0; while (id < MAX_INPUT_DEV_NUM) { - if (cachedInfo[id].devName == NULL) { + if (g_cachedInfo[id] == NULL) { return id; } id++; @@ -55,24 +55,48 @@ static int cachedPosId(void) return HDF_FAILURE; } -void GetInfoFromHid(HidInfo info) +void SendInfoToHdf(HidInfo *info) { + int ret; int32_t id = cachedPosId(); if (id == HDF_FAILURE) { HDF_LOGE("%s: cached hid info failed", __func__); return; } - cachedInfo[id] = info; + g_cachedInfo[id] = (HidInfo *)OsalMemAlloc(sizeof(HidInfo)); + if (g_cachedInfo[id] == NULL) { + HDF_LOGE("%s: malloc failed", __func__); + return; + } + ret = memcpy_s(g_cachedInfo[id], sizeof(HidInfo), info, sizeof(HidInfo)); + if (ret != 0) { + HDF_LOGE("%s: memcpy failed", __func__); + OsalMemFree(g_cachedInfo[id]); + g_cachedInfo[id] = NULL; + return; + } +} + +static void FreeCachedInfo() +{ + int32_t id = 0; + while (id < MAX_INPUT_DEV_NUM) { + if (g_cachedInfo[id] != NULL) { + OsalMemFree(g_cachedInfo[id]); + g_cachedInfo[id] = NULL; + } + id++; + } } static void SetInputDevAbility(InputDevice *inputDev) { - HidInfo info; + HidInfo *info = NULL; int32_t id = 0; uint32_t len; while (id < MAX_INPUT_DEV_NUM) { - if(cachedInfo[id].devName != NULL && !strcmp(inputDev->devName, cachedInfo[id].devName)) { - info = cachedInfo[id]; + if(g_cachedInfo[id] != NULL && !strcmp(inputDev->devName, g_cachedInfo[id]->devName)) { + info = g_cachedInfo[id]; break; } id++; @@ -83,35 +107,35 @@ static void SetInputDevAbility(InputDevice *inputDev) } len = sizeof(unsigned long); memcpy_s(inputDev->abilitySet.devProp, len * BITS_TO_LONG(INPUT_PROP_CNT), - info.devProp, len * BITS_TO_LONG(INPUT_PROP_CNT)); + info->devProp, len * BITS_TO_LONG(INPUT_PROP_CNT)); memcpy_s(inputDev->abilitySet.eventType, len * BITS_TO_LONG(EV_CNT), - info.eventType, len * BITS_TO_LONG(EV_CNT)); + info->eventType, len * BITS_TO_LONG(EV_CNT)); memcpy_s(inputDev->abilitySet.absCode, len * BITS_TO_LONG(ABS_CNT), - info.absCode, len * BITS_TO_LONG(ABS_CNT)); + info->absCode, len * BITS_TO_LONG(ABS_CNT)); memcpy_s(inputDev->abilitySet.relCode, len * BITS_TO_LONG(REL_CNT), - info.relCode, len * BITS_TO_LONG(REL_CNT)); + info->relCode, len * BITS_TO_LONG(REL_CNT)); memcpy_s(inputDev->abilitySet.keyCode, len * BITS_TO_LONG(KEY_CNT), - info.keyCode, len * BITS_TO_LONG(KEY_CNT)); + info->keyCode, len * BITS_TO_LONG(KEY_CNT)); memcpy_s(inputDev->abilitySet.ledCode, len * BITS_TO_LONG(LED_CNT), - info.ledCode, len * BITS_TO_LONG(LED_CNT)); + info->ledCode, len * BITS_TO_LONG(LED_CNT)); memcpy_s(inputDev->abilitySet.miscCode, len * BITS_TO_LONG(MSC_CNT), - info.miscCode, len * BITS_TO_LONG(MSC_CNT)); + info->miscCode, len * BITS_TO_LONG(MSC_CNT)); memcpy_s(inputDev->abilitySet.soundCode, len * BITS_TO_LONG(SND_CNT), - info.soundCode, len * BITS_TO_LONG(SND_CNT)); + info->soundCode, len * BITS_TO_LONG(SND_CNT)); memcpy_s(inputDev->abilitySet.forceCode, len * BITS_TO_LONG(FF_CNT), - info.forceCode, len * BITS_TO_LONG(FF_CNT)); + info->forceCode, len * BITS_TO_LONG(FF_CNT)); memcpy_s(inputDev->abilitySet.switchCode, len * BITS_TO_LONG(SW_CNT), - info.switchCode, len * BITS_TO_LONG(SW_CNT)); + info->switchCode, len * BITS_TO_LONG(SW_CNT)); - inputDev->attrSet.id.busType = info.bustype; - inputDev->attrSet.id.vendor = info.vendor; - inputDev->attrSet.id.product = info.product; - inputDev->attrSet.id.version = info.version; + inputDev->attrSet.id.busType = info->bustype; + inputDev->attrSet.id.vendor = info->vendor; + inputDev->attrSet.id.product = info->product; + inputDev->attrSet.id.version = info->version; - cachedInfo[id].devName = NULL; + FreeCachedInfo(); } -static InputDevice* HidConstructInputDev(HidInfo info) +static InputDevice* HidConstructInputDev(HidInfo *info) { InputDevice *inputDev = (InputDevice *)OsalMemAlloc(sizeof(InputDevice)); if (inputDev == NULL) { @@ -120,28 +144,25 @@ static InputDevice* HidConstructInputDev(HidInfo info) } (void)memset_s(inputDev, sizeof(InputDevice), 0, sizeof(InputDevice)); - inputDev->devType = info.devType; - inputDev->devName = info.devName; + inputDev->devType = info->devType; + inputDev->devName = info->devName; SetInputDevAbility(inputDev); return inputDev; } -static InputDevice* DoRegisterInputDev(InputDevice* inputDev) +static void DoRegisterInputDev(InputDevice* inputDev) { int32_t ret; - ret = RegisterInputDevice(inputDev); - if (ret == HDF_SUCCESS) { - return inputDev; - } else { + if (ret != HDF_SUCCESS) { OsalMemFree(inputDev); inputDev = NULL; - return NULL; + return; } } -static InputDevice* CacheHid(InputDevice* inputDev) +static void CacheHid(InputDevice* inputDev) { int32_t i = 0; while ((i < MAX_INPUT_DEV_NUM) && (cachedHid[i] != NULL)) { @@ -149,9 +170,10 @@ static InputDevice* CacheHid(InputDevice* inputDev) } if (i < MAX_INPUT_DEV_NUM) { cachedHid[i] = inputDev; - return inputDev; + return; + } else { + HDF_LOGE("%s: cached hid device failed", __func__); } - return NULL; } static bool InputDriverLoaded(void) @@ -163,7 +185,7 @@ static bool InputDriverLoaded(void) return false; } -void* HidRegisterHdfInputDev(HidInfo info) +void* HidRegisterHdfInputDev(HidInfo *info) { InputDevice* inputDev = HidConstructInputDev(info); if (inputDev == NULL) { @@ -172,10 +194,11 @@ void* HidRegisterHdfInputDev(HidInfo info) } if (InputDriverLoaded()) { - return DoRegisterInputDev(inputDev); + DoRegisterInputDev(inputDev); } else { - return CacheHid(inputDev); + CacheHid(inputDev); } + return inputDev; } void HidUnregisterHdfInputDev(const void *inputDev) @@ -338,11 +361,21 @@ static int32_t HdfHIDDriverBind(struct HdfDeviceObject *device) return HDF_SUCCESS; } +static void HdfHIDDriverRelease(struct HdfDeviceObject *device) +{ + FreeCachedInfo(); + if (device == NULL) { + HDF_LOGE("%s: device is null", __func__); + return; + } +} + struct HdfDriverEntry g_hdfHIDEntry = { .moduleVersion = 1, .moduleName = "HDF_HID", .Bind = HdfHIDDriverBind, .Init = HdfHIDDriverInit, + .Release = HdfHIDDriverRelease, }; HDF_INIT(g_hdfHIDEntry); diff --git a/model/input/driver/hdf_hid_adapter.h b/model/input/driver/hdf_hid_adapter.h index 67285c3856daf97c47b13764b6ae52c8e57386be..487a047e2812a6686e66abb6a041e5d93b106922 100644 --- a/model/input/driver/hdf_hid_adapter.h +++ b/model/input/driver/hdf_hid_adapter.h @@ -73,8 +73,8 @@ enum HidType { HID_TYPE_UNKNOWN, /* Unknown input device type */ }; -void GetInfoFromHid(HidInfo info); -void* HidRegisterHdfInputDev(HidInfo dev); +void SendInfoToHdf(HidInfo *info); +void* HidRegisterHdfInputDev(HidInfo *dev); 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 028d802af36cad6543f48250c809580e8a07ce01..4d449b6c1f15f244830ab4fc24f438e42eb16435 100644 --- a/model/input/driver/hdf_input_device_manager.c +++ b/model/input/driver/hdf_input_device_manager.c @@ -62,13 +62,11 @@ static struct HdfDeviceObject *HidRegisterHdfDevice(InputDevice *inputDev) static void HotPlugNotify(const InputDevice *inputDev, uint32_t status) { - struct HdfSBuf *sbuf = NULL; HotPlugEvent event = {0}; int32_t ret; - sbuf = HdfSBufObtain(sizeof(HotPlugEvent)); - if (sbuf == NULL) { - HDF_LOGE("%s: obtain buffer failed", __func__); + if (inputDev->eventBuf == NULL) { + HDF_LOGE("%s: event buffer is null", __func__); return; } @@ -76,16 +74,16 @@ static void HotPlugNotify(const InputDevice *inputDev, uint32_t status) event.devType = inputDev->devType; event.status = status; - if (!HdfSbufWriteBuffer(sbuf, &event, sizeof(HotPlugEvent))) { + if (!HdfSbufWriteBuffer(inputDev->eventBuf, &event, sizeof(HotPlugEvent))) { HDF_LOGE("%s: write buffer failed", __func__); - HdfSbufFlush(sbuf); + HdfSbufFlush(inputDev->eventBuf); return; } - ret = HdfDeviceSendEvent(g_inputManager->hdfDevObj, 0, sbuf); + ret = HdfDeviceSendEvent(g_inputManager->hdfDevObj, 0, inputDev->eventBuf); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: send event failed", __func__); } - HdfSbufFlush(sbuf); + HdfSbufFlush(inputDev->eventBuf); } static int32_t CreateDeviceNode(InputDevice *inputDev) @@ -230,6 +228,11 @@ static int32_t AllocPackageBuffer(InputDevice *inputDev) HDF_LOGE("%s: malloc sbuf failed", __func__); return HDF_ERR_MALLOC_FAIL; } + inputDev->eventBuf = HdfSBufObtain(sizeof(HotPlugEvent)); + if (inputDev->eventBuf == NULL) { + HDF_LOGE("%s: malloc sbuf failed", __func__); + return HDF_ERR_MALLOC_FAIL; + } inputDev->pkgNum = pkgNum; return HDF_SUCCESS; } @@ -320,12 +323,14 @@ void UnregisterInputDevice(InputDevice *inputDev) } DeleteDeviceNode(inputDev); - OsalMemFree(inputDev->pkgBuf); + HdfSBufRecycle(inputDev->pkgBuf); inputDev->pkgBuf = NULL; ret = DeleteInputDevice(inputDev); if (ret != HDF_SUCCESS) { goto EXIT; } + HdfSBufRecycle(inputDev->eventBuf); + inputDev->eventBuf = NULL; OsalMemFree(inputDev); inputDev = NULL; OsalMutexUnlock(&g_inputManager->mutex); diff --git a/model/input/driver/hdf_input_device_manager.h b/model/input/driver/hdf_input_device_manager.h index 713784ce0b2e63f48be9b2b99bde7b41e5148d2d..8b959bd7d480efb639a6650b1c4416eebe992ed8 100644 --- a/model/input/driver/hdf_input_device_manager.h +++ b/model/input/driver/hdf_input_device_manager.h @@ -20,7 +20,7 @@ #define HDF_LOG_TAG HDF_INPUT_DRV #define INPUT_DEV_PATH_LEN 64 #define MAX_INPUT_DEV_NUM 32 -#define DEV_NAME_LEN 32 +#define DEV_NAME_LEN 64 #define ONLINE 0 #define OFFLINE 1 @@ -108,6 +108,7 @@ typedef struct InputDeviceInfo { uint16_t pkgCount; bool errFrameFlag; struct HdfSBuf *pkgBuf; + struct HdfSBuf *eventBuf; void *pvtData; DevAttr attrSet; DevAbility abilitySet; diff --git a/model/input/driver/touchscreen/touch_gt911.c b/model/input/driver/touchscreen/touch_gt911.c index fb935966bca2ddb6fcbb8b0cebd7e7b7a0c5ee43..c25c7c09900e0a18e746c6392e942e43ff9990ad 100644 --- a/model/input/driver/touchscreen/touch_gt911.c +++ b/model/input/driver/touchscreen/touch_gt911.c @@ -15,9 +15,9 @@ #include "touch_gt911.h" #define AXIS_X_MAX 479 -#define AXIS_X_RANGE 480 +#define AXIS_X_RANGE 0 #define AXIS_Y_MAX 959 -#define AXIS_Y_RANGE 960 +#define AXIS_Y_RANGE 0 #define MAX_POINT 5 static int32_t ChipInit(ChipDevice *device)