From 55d6ca11a7b304124da1144dc1264c0509b9b276 Mon Sep 17 00:00:00 2001 From: huangkai71 Date: Wed, 7 Jul 2021 02:52:15 +0000 Subject: [PATCH] update code from STD Signed-off-by: huangkai71 --- model/input/driver/hdf_hid_adapter.c | 115 +++++++++++++++++- model/input/driver/hdf_input_device_manager.c | 10 +- model/input/driver/hdf_input_device_manager.h | 2 +- model/input/driver/hdf_touch.c | 11 +- model/input/driver/touchscreen/touch_gt911.c | 21 ++++ 5 files changed, 143 insertions(+), 16 deletions(-) diff --git a/model/input/driver/hdf_hid_adapter.c b/model/input/driver/hdf_hid_adapter.c index c11238b68..47496b8a6 100644 --- a/model/input/driver/hdf_hid_adapter.c +++ b/model/input/driver/hdf_hid_adapter.c @@ -203,14 +203,127 @@ static int32_t HdfHIDDriverInit(struct HdfDeviceObject *device) return HDF_SUCCESS; } +static int32_t HidGetDevType(InputDevice *inputDev, struct HdfSBuf *reply) +{ + uint32_t devType = inputDev->devType; + HDF_LOGI("%s: enter, devType is %u", __func__, devType); + bool ret = HdfSbufWriteUint32(reply, devType); + if (!ret) { + HDF_LOGE("%s: HdfSbufWriteUint32 failed", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +static int32_t HidGetDeviceStrInfo(InputDevice *inputDev, int32_t cmd, struct HdfSBuf *reply) +{ + const char *info = NULL; + if (inputDev == NULL) { + HDF_LOGE("%s: parameter invalid", __func__); + return HDF_ERR_INVALID_PARAM; + } + + switch (cmd) { + case GET_CHIP_NAME: + info = "null"; + break; + case GET_VENDOR_NAME: + info = "null"; + break; + case GET_CHIP_INFO: + info = "null"; + break; + default: + info = NULL; + break; + } + + bool ret = HdfSbufWriteString(reply, info); + if (!ret) { + HDF_LOGE("%s: HdfSbufWriteUint32 failed", __func__); + return HDF_FAILURE; + } + HDF_LOGI("%s: cmd is %d, the info is %s", __func__, cmd, info); + return HDF_SUCCESS; +} + +static int32_t HidGetDeviceAttr(InputDevice *inputDev, struct HdfSBuf *reply) +{ + int32_t ret; + if (inputDev == NULL) { + return HDF_FAILURE; + } + + HDF_LOGE("%s: enter", __func__); + ret = strncpy_s(inputDev->attrSet.devName, DEV_NAME_LEN, inputDev->devName, strlen(inputDev->devName)); + if (ret) { + HDF_LOGE("%s: copy name from inputDev failed, ret = %d", __func__, ret); + return HDF_FAILURE; + } + + if (!HdfSbufWriteBuffer(reply, &inputDev->attrSet, sizeof(DevAttr))) { + HDF_LOGE("%s: sbuf write dev attr failed", __func__); + return HDF_FAILURE; + } + + HDF_LOGI("%s: get dev attr succ", __func__); + return HDF_SUCCESS; +} + +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; +} + static int32_t HdfHIDDispatch(struct HdfDeviceIoClient *client, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply) { (void)cmd; + int32_t ret; + InputDevice *inputDev = NULL; if (client == NULL || data == NULL || reply == NULL) { HDF_LOGE("%s: param is null", __func__); return HDF_FAILURE; } - return HDF_SUCCESS; + + inputDev = (InputDevice *)client->device->priv; + if (inputDev == NULL) { + HDF_LOGE("%s: inputDev is null", __func__); + return HDF_FAILURE; + } + + HDF_LOGI("%s: cmd = %d", __func__, cmd); + switch (cmd) { + case GET_DEV_TYPE: + ret = HidGetDevType(inputDev, reply); + break; + case GET_CHIP_NAME: + case GET_VENDOR_NAME: + case GET_CHIP_INFO: + ret = HidGetDeviceStrInfo(inputDev, cmd, reply); + break; + case GET_DEV_ATTR: + ret = HidGetDeviceAttr(inputDev, reply); + break; + case GET_DEV_ABILITY: + ret = HidGetDeviceAbility(inputDev, reply); + break; + default: + ret = HDF_SUCCESS; + HDF_LOGE("%s: cmd unknown, cmd = 0x%x", __func__, cmd); + break; + } + return ret; } static int32_t HdfHIDDriverBind(struct HdfDeviceObject *device) diff --git a/model/input/driver/hdf_input_device_manager.c b/model/input/driver/hdf_input_device_manager.c index 2db56fd80..0407f0692 100644 --- a/model/input/driver/hdf_input_device_manager.c +++ b/model/input/driver/hdf_input_device_manager.c @@ -60,7 +60,7 @@ static struct HdfDeviceObject *HidRegisterHdfDevice(InputDevice *inputDev) return hdfDev; } -static void HotPlugNotify(const InputDevice *inputDev, bool status) +static void HotPlugNotify(const InputDevice *inputDev, uint32_t status) { struct HdfSBuf *sbuf = NULL; HotPlugEvent event = {0}; @@ -71,20 +71,21 @@ static void HotPlugNotify(const InputDevice *inputDev, bool status) HDF_LOGE("%s: obtain buffer failed", __func__); return; } + event.devId = inputDev->devId; event.devType = inputDev->devType; event.status = status; if (!HdfSbufWriteBuffer(sbuf, &event, sizeof(HotPlugEvent))) { HDF_LOGE("%s: write buffer failed", __func__); - goto EXIT; + HdfSbufFlush(sbuf); + return; } ret = HdfDeviceSendEvent(g_inputManager->hdfDevObj, 0, sbuf); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: send event failed", __func__); } -EXIT: - HdfSBufRecycle(sbuf); + HdfSbufFlush(sbuf); } static int32_t CreateDeviceNode(InputDevice *inputDev) @@ -92,6 +93,7 @@ static int32_t CreateDeviceNode(InputDevice *inputDev) if (IsHidDevice(inputDev->devType)) { HDF_LOGI("%s: prepare to register hdf device", __func__); inputDev->hdfDevObj = HidRegisterHdfDevice(inputDev); + inputDev->hdfDevObj->priv = (void *)inputDev; if (inputDev->hdfDevObj == NULL) { return HDF_DEV_ERR_NO_DEVICE; } diff --git a/model/input/driver/hdf_input_device_manager.h b/model/input/driver/hdf_input_device_manager.h index bed6437fb..713784ce0 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 16 +#define DEV_NAME_LEN 32 #define ONLINE 0 #define OFFLINE 1 diff --git a/model/input/driver/hdf_touch.c b/model/input/driver/hdf_touch.c index 6d32d162e..ad862cbd8 100644 --- a/model/input/driver/hdf_touch.c +++ b/model/input/driver/hdf_touch.c @@ -19,10 +19,7 @@ #define MAX_TOUCH_DEVICE 5 #define REGISTER_BYTE_SIZE 4 #define TOUCH_CHIP_NAME_LEN 10 -#define AXIS_X_MAX 479 -#define AXIS_X_RANGE 480 -#define AXIS_Y_MAX 959 -#define AXIS_Y_RANGE 960 + static TouchDriver *g_touchDriverList[MAX_TOUCH_DEVICE]; static void InputFrameReport(TouchDriver *driver); @@ -460,12 +457,6 @@ static int32_t TouchGetDeviceAttr(TouchDriver *driver, struct HdfSBuf *reply) HDF_LOGE("%s: enter", __func__); char *tempStr = "main_touch"; (void)strncpy_s(driver->inputDev->attrSet.devName, DEV_NAME_LEN, tempStr, strlen(tempStr)); - driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_X].min = 0; - driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_X].max = AXIS_X_MAX; - driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_X].range = AXIS_X_RANGE; - driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_Y].min = 0; - driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_Y].max = AXIS_Y_MAX; - driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_Y].range = AXIS_Y_RANGE; if (!HdfSbufWriteBuffer(reply, &driver->inputDev->attrSet, sizeof(DevAttr))) { HDF_LOGE("%s: sbuf write dev attr failed", __func__); diff --git a/model/input/driver/touchscreen/touch_gt911.c b/model/input/driver/touchscreen/touch_gt911.c index 014ad7ed8..fb935966b 100644 --- a/model/input/driver/touchscreen/touch_gt911.c +++ b/model/input/driver/touchscreen/touch_gt911.c @@ -14,6 +14,12 @@ #include "input_i2c_ops.h" #include "touch_gt911.h" +#define AXIS_X_MAX 479 +#define AXIS_X_RANGE 480 +#define AXIS_Y_MAX 959 +#define AXIS_Y_RANGE 960 +#define MAX_POINT 5 + static int32_t ChipInit(ChipDevice *device) { return HDF_SUCCESS; @@ -179,7 +185,22 @@ static void SetAbility(ChipDevice *device) device->driver->inputDev->abilitySet.eventType[0] = SET_BIT(EV_SYN) | SET_BIT(EV_KEY) | SET_BIT(EV_ABS); device->driver->inputDev->abilitySet.absCode[0] = SET_BIT(ABS_X) | SET_BIT(ABS_Y); + device->driver->inputDev->abilitySet.absCode[1] = SET_BIT(ABS_MT_POSITION_X) | + SET_BIT(ABS_MT_POSITION_Y) | SET_BIT(ABS_MT_TRACKING_ID); device->driver->inputDev->abilitySet.keyCode[3] = SET_BIT(KEY_UP) | SET_BIT(KEY_DOWN); + device->driver->inputDev->attrSet.axisInfo[ABS_X].min = 0; + device->driver->inputDev->attrSet.axisInfo[ABS_X].max = AXIS_X_MAX; + device->driver->inputDev->attrSet.axisInfo[ABS_X].range = AXIS_X_RANGE; + device->driver->inputDev->attrSet.axisInfo[ABS_Y].min = 0; + device->driver->inputDev->attrSet.axisInfo[ABS_Y].max = AXIS_Y_MAX; + device->driver->inputDev->attrSet.axisInfo[ABS_Y].range = AXIS_Y_RANGE; + device->driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_X].min = 0; + device->driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_X].max = AXIS_X_MAX; + device->driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_X].range = AXIS_X_RANGE; + device->driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_Y].min = 0; + device->driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_Y].max = AXIS_Y_MAX; + device->driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_Y].range = AXIS_Y_RANGE; + device->driver->inputDev->attrSet.axisInfo[ABS_MT_TRACKING_ID].max = MAX_POINT; } static struct TouchChipOps g_gt911ChipOps = { -- Gitee