From 27317472053517478286a46c97856b89e0544c90 Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Tue, 20 Jul 2021 02:47:41 +0000 Subject: [PATCH 1/3] sync code from std Signed-off-by: YOUR_NAME --- model/input/driver/hdf_hid_adapter.c | 87 +++++++++++-------- model/input/driver/hdf_hid_adapter.h | 4 +- model/input/driver/hdf_input_device_manager.c | 23 +++-- model/input/driver/hdf_input_device_manager.h | 3 +- model/input/driver/touchscreen/touch_gt911.c | 4 +- 5 files changed, 70 insertions(+), 51 deletions(-) diff --git a/model/input/driver/hdf_hid_adapter.c b/model/input/driver/hdf_hid_adapter.c index 47496b8a6..59b4ad702 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,36 @@ 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 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 +95,36 @@ 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; + OsalMemFree(g_cachedInfo[id]); + g_cachedInfo[id] = NULL; } -static InputDevice* HidConstructInputDev(HidInfo info) +static InputDevice* HidConstructInputDev(HidInfo *info) { InputDevice *inputDev = (InputDevice *)OsalMemAlloc(sizeof(InputDevice)); if (inputDev == NULL) { @@ -120,28 +133,26 @@ 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 +160,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 +175,7 @@ static bool InputDriverLoaded(void) return false; } -void* HidRegisterHdfInputDev(HidInfo info) +void* HidRegisterHdfInputDev(HidInfo *info) { InputDevice* inputDev = HidConstructInputDev(info); if (inputDev == NULL) { @@ -172,10 +184,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) diff --git a/model/input/driver/hdf_hid_adapter.h b/model/input/driver/hdf_hid_adapter.h index 67285c385..487a047e2 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 028d802af..4d449b6c1 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 713784ce0..8b959bd7d 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 fb935966b..c25c7c099 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) -- Gitee From fe4542116bc1388691f37b4f61068c362ebe3bab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=87=AF?= Date: Tue, 20 Jul 2021 04:42:39 +0000 Subject: [PATCH 2/3] update model/input/driver/hdf_hid_adapter.c. --- model/input/driver/hdf_hid_adapter.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/model/input/driver/hdf_hid_adapter.c b/model/input/driver/hdf_hid_adapter.c index 59b4ad702..6f5a0df34 100644 --- a/model/input/driver/hdf_hid_adapter.c +++ b/model/input/driver/hdf_hid_adapter.c @@ -77,6 +77,18 @@ void SendInfoToHdf(HidInfo *info) } } +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 = NULL; @@ -120,8 +132,7 @@ static void SetInputDevAbility(InputDevice *inputDev) inputDev->attrSet.id.product = info->product; inputDev->attrSet.id.version = info->version; - OsalMemFree(g_cachedInfo[id]); - g_cachedInfo[id] = NULL; + FreeCachedInfo(); } static InputDevice* HidConstructInputDev(HidInfo *info) @@ -133,7 +144,6 @@ static InputDevice* HidConstructInputDev(HidInfo *info) } (void)memset_s(inputDev, sizeof(InputDevice), 0, sizeof(InputDevice)); - inputDev->devType = info->devType; inputDev->devName = info->devName; SetInputDevAbility(inputDev); -- Gitee From 345c97818531cb371b4a0851d9951ae63130ea1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=87=AF?= Date: Tue, 20 Jul 2021 06:16:10 +0000 Subject: [PATCH 3/3] update model/input/driver/hdf_hid_adapter.c. --- model/input/driver/hdf_hid_adapter.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/model/input/driver/hdf_hid_adapter.c b/model/input/driver/hdf_hid_adapter.c index 6f5a0df34..bfd7a771a 100644 --- a/model/input/driver/hdf_hid_adapter.c +++ b/model/input/driver/hdf_hid_adapter.c @@ -361,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); -- Gitee