From 8fe00e0578b1de347cc1b64753e2c1cec97e6bf8 Mon Sep 17 00:00:00 2001 From: kevin Date: Thu, 1 Jul 2021 15:15:52 +0800 Subject: [PATCH 1/2] sync master vibrator to 2.2beta branch Signed-off-by: kevin Change-Id: I9df39a248d099b2ee47e03a3787a627882e9226e --- .../test/unittest/common/hdf_config_test.cpp | 82 ++-- .../test/unittest/common/hdf_sbuf_test.cpp | 4 +- .../driver/chipset/vibrator_linear_driver.c | 178 ++++++++ .../driver/chipset/vibrator_linear_driver.h | 24 ++ .../vibrator/driver/include/vibrator_driver.h | 46 ++ .../driver/include/vibrator_driver_type.h | 60 +++ .../vibrator/driver/include/vibrator_haptic.h | 62 +++ .../vibrator/driver/src/vibrator_driver.c | 314 ++++++++++++++ .../vibrator/driver/src/vibrator_haptic.c | 396 ++++++++++++++++++ 9 files changed, 1123 insertions(+), 43 deletions(-) create mode 100644 model/misc/vibrator/driver/chipset/vibrator_linear_driver.c create mode 100644 model/misc/vibrator/driver/chipset/vibrator_linear_driver.h create mode 100644 model/misc/vibrator/driver/include/vibrator_driver.h create mode 100644 model/misc/vibrator/driver/include/vibrator_driver_type.h create mode 100644 model/misc/vibrator/driver/include/vibrator_haptic.h create mode 100644 model/misc/vibrator/driver/src/vibrator_driver.c create mode 100644 model/misc/vibrator/driver/src/vibrator_haptic.c diff --git a/ability/config/test/unittest/common/hdf_config_test.cpp b/ability/config/test/unittest/common/hdf_config_test.cpp index f8cd98cdb..75f6541c1 100644 --- a/ability/config/test/unittest/common/hdf_config_test.cpp +++ b/ability/config/test/unittest/common/hdf_config_test.cpp @@ -94,7 +94,7 @@ void HdfConfigTest::TearDown() {} * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestCreateDMHslToTree001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestCreateDMHslToTree001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_CREATE_DM_HSL_TO_TREE_001, HDF_MSG_RESULT_DEFAULT}; printf("HdfConfigTest enter\n\r"); @@ -107,7 +107,7 @@ HWTEST_F(HdfConfigTest, HslTestCreateDMHslToTree001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetNodeByMatchAttrSuccess001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetNodeByMatchAttrSuccess001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -119,7 +119,7 @@ HWTEST_F(HdfConfigTest, HslTestGetNodeByMatchAttrSuccess001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetNodeByMatchAttrFail001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetNodeByMatchAttrFail001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -131,7 +131,7 @@ HWTEST_F(HdfConfigTest, HslTestGetNodeByMatchAttrFail001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetBoolAttrValueSuccess001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetBoolAttrValueSuccess001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_BOOL_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -143,7 +143,7 @@ HWTEST_F(HdfConfigTest, HslTestGetBoolAttrValueSuccess001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetBoolAttrValueFail001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetBoolAttrValueFail001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_BOOL_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -155,7 +155,7 @@ HWTEST_F(HdfConfigTest, HslTestGetBoolAttrValueFail001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint8AttrValueSuccess001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetUint8AttrValueSuccess001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -167,7 +167,7 @@ HWTEST_F(HdfConfigTest, HslTestGetUint8AttrValueSuccess001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint8AttrValueFail001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetUint8AttrValueFail001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -179,7 +179,7 @@ HWTEST_F(HdfConfigTest, HslTestGetUint8AttrValueFail001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayElemSuccess001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayElemSuccess001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -191,7 +191,7 @@ HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayElemSuccess001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayElemFail001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayElemFail001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -203,7 +203,7 @@ HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayElemFail001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint8ArraySuccess001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetUint8ArraySuccess001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -215,7 +215,7 @@ HWTEST_F(HdfConfigTest, HslTestGetUint8ArraySuccess001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayFail001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayFail001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -227,7 +227,7 @@ HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayFail001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint16AttrValueSuccess001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetUint16AttrValueSuccess001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -239,7 +239,7 @@ HWTEST_F(HdfConfigTest, HslTestGetUint16AttrValueSuccess001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint16AttrValueFail001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetUint16AttrValueFail001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -251,7 +251,7 @@ HWTEST_F(HdfConfigTest, HslTestGetUint16AttrValueFail001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayElemSuccess001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayElemSuccess001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -264,7 +264,7 @@ HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayElemSuccess001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayElemFail001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayElemFail001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -276,7 +276,7 @@ HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayElemFail001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint16ArraySuccess001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetUint16ArraySuccess001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -288,7 +288,7 @@ HWTEST_F(HdfConfigTest, HslTestGetUint16ArraySuccess001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayFail001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayFail001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -300,7 +300,7 @@ HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayFail001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint32AttrValueSuccess001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetUint32AttrValueSuccess001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -312,7 +312,7 @@ HWTEST_F(HdfConfigTest, HslTestGetUint32AttrValueSuccess001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint32AttrValueFail001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetUint32AttrValueFail001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -324,7 +324,7 @@ HWTEST_F(HdfConfigTest, HslTestGetUint32AttrValueFail001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayElemSuccess001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayElemSuccess001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -337,7 +337,7 @@ HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayElemSuccess001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayElemFail001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayElemFail001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -349,7 +349,7 @@ HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayElemFail001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint32ArraySuccess001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetUint32ArraySuccess001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -361,7 +361,7 @@ HWTEST_F(HdfConfigTest, HslTestGetUint32ArraySuccess001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayFail001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayFail001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -373,7 +373,7 @@ HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayFail001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint64AttrValueSuccess001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetUint64AttrValueSuccess001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -385,7 +385,7 @@ HWTEST_F(HdfConfigTest, HslTestGetUint64AttrValueSuccess001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint64AttrValueFail001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetUint64AttrValueFail001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -397,7 +397,7 @@ HWTEST_F(HdfConfigTest, HslTestGetUint64AttrValueFail001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayElemSuccess001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayElemSuccess001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -410,7 +410,7 @@ HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayElemSuccess001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayElemFail001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayElemFail001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -422,7 +422,7 @@ HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayElemFail001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint64ArraySuccess001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetUint64ArraySuccess001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -434,7 +434,7 @@ HWTEST_F(HdfConfigTest, HslTestGetUint64ArraySuccess001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayFail001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayFail001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -446,7 +446,7 @@ HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayFail001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetElemNumSuccess001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetElemNumSuccess001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_ELEM_NUM_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -458,7 +458,7 @@ HWTEST_F(HdfConfigTest, HslTestGetElemNumSuccess001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetElemNumFail001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetElemNumFail001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_ELEM_NUM_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -470,7 +470,7 @@ HWTEST_F(HdfConfigTest, HslTestGetElemNumFail001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetChildNodeSuccess001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetChildNodeSuccess001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_CHILD_NODE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -482,7 +482,7 @@ HWTEST_F(HdfConfigTest, HslTestGetChildNodeSuccess001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetChildNodeFail001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetChildNodeFail001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_CHILD_NODE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -494,7 +494,7 @@ HWTEST_F(HdfConfigTest, HslTestGetChildNodeFail001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestTraverseAttrInNodeSuccess001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestTraverseAttrInNodeSuccess001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_TRAVERSE_ATTR_IN_NODE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -506,7 +506,7 @@ HWTEST_F(HdfConfigTest, HslTestTraverseAttrInNodeSuccess001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestTraverseAttrInNodeFail001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestTraverseAttrInNodeFail001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_TRAVERSE_ATTR_IN_NODE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -518,7 +518,7 @@ HWTEST_F(HdfConfigTest, HslTestTraverseAttrInNodeFail001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetStringSuccess001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetStringSuccess001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -530,7 +530,7 @@ HWTEST_F(HdfConfigTest, HslTestGetStringSuccess001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetStringFail001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetStringFail001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -542,7 +542,7 @@ HWTEST_F(HdfConfigTest, HslTestGetStringFail001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetStringArrayElemSuccess001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetStringArrayElemSuccess001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -555,7 +555,7 @@ HWTEST_F(HdfConfigTest, HslTestGetStringArrayElemSuccess001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetStringArrayElemFail001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetStringArrayElemFail001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -567,7 +567,7 @@ HWTEST_F(HdfConfigTest, HslTestGetStringArrayElemFail001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetNodeAttrRefSuccess001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetNodeAttrRefSuccess001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_REF_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); @@ -579,7 +579,7 @@ HWTEST_F(HdfConfigTest, HslTestGetNodeAttrRefSuccess001, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetNodeAttrRefFail001, TestSize.Level0) +HWTEST_F(HdfConfigTest, HslTestGetNodeAttrRefFail001, TestSize.Level1) { struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_REF_002, HDF_MSG_RESULT_DEFAULT}; printf("HdfConfigTest last enter\n\r"); diff --git a/core/manager/test/unittest/common/hdf_sbuf_test.cpp b/core/manager/test/unittest/common/hdf_sbuf_test.cpp index 4b5a97954..a1f482257 100644 --- a/core/manager/test/unittest/common/hdf_sbuf_test.cpp +++ b/core/manager/test/unittest/common/hdf_sbuf_test.cpp @@ -672,7 +672,7 @@ HWTEST_F(HdfSBufTest, SbufTestNullBuffer015, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000F869B */ -HWTEST_F(HdfSBufTest, SbufTestRandomDataSeq016, TestSize.Level1) +HWTEST_F(HdfSBufTest, SbufTestRandomDataSeq016, TestSize.Level0) { HdfSBuf *sBuf = HdfSBufObtainDefaultSize(); ASSERT_NE(sBuf, nullptr); @@ -697,7 +697,7 @@ HWTEST_F(HdfSBufTest, SbufTestRandomDataSeq016, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000F869B */ -HWTEST_F(HdfSBufTest, SbufTestRandomRWDataSeq017, TestSize.Level1) +HWTEST_F(HdfSBufTest, SbufTestRandomRWDataSeq017, TestSize.Level0) { HdfSBuf *sBuf = HdfSBufObtainDefaultSize(); ASSERT_NE(sBuf, nullptr); diff --git a/model/misc/vibrator/driver/chipset/vibrator_linear_driver.c b/model/misc/vibrator/driver/chipset/vibrator_linear_driver.c new file mode 100644 index 000000000..bb7859a6c --- /dev/null +++ b/model/misc/vibrator/driver/chipset/vibrator_linear_driver.c @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#include "device_resource_if.h" +#include "gpio_if.h" +#include "hdf_base.h" +#include "hdf_device_desc.h" +#include "osal_mem.h" +#include "securec.h" +#include "vibrator_driver.h" +#include "vibrator_driver_type.h" +#include "vibrator_linear_driver.h" + +#define HDF_LOG_TAG vibrator_linear_driver_c + +struct VibratorLinearDriverData *g_linearVibratorData = NULL; +static struct VibratorLinearDriverData *GetLinearVibratorData(void) +{ + return g_linearVibratorData; +} + +static int32_t StartLinearVibrator() +{ + int32_t ret; + struct VibratorLinearDriverData *drvData = GetLinearVibratorData(); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(drvData, HDF_FAILURE); + + if (drvData->busType != VIBRATOR_BUS_GPIO) { + HDF_LOGE("%s: vibrator bus type not gpio", __func__); + return HDF_FAILURE; + } + + ret = GpioWrite(drvData->gpioNum, GPIO_VAL_LOW); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: pull gpio%d to %d level failed", __func__, drvData->gpioNum, GPIO_VAL_LOW); + return ret; + } + return HDF_SUCCESS; +} + +static int32_t StartEffectLinearVibrator(uint32_t effectType) +{ + (void)effectType; + HDF_LOGE("%s: vibrator set build-in effect no support!", __func__); + return HDF_SUCCESS; +} + +static int32_t StopLinearVibrator() +{ + int32_t ret; + struct VibratorLinearDriverData *drvData = GetLinearVibratorData(); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(drvData, HDF_FAILURE); + + if (drvData->busType != VIBRATOR_BUS_GPIO) { + HDF_LOGE("%s: vibrator bus type not gpio", __func__); + return HDF_FAILURE; + } + + ret = GpioWrite(drvData->gpioNum, GPIO_VAL_HIGH); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: pull gpio%d to %d level failed", __func__, drvData->gpioNum, GPIO_VAL_HIGH); + return ret; + } + return HDF_SUCCESS; +} + +static int32_t DispatchLinearVibrator(struct HdfDeviceIoClient *client, + int32_t cmd, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + (void)client; + (void)cmd; + (void)data; + (void)reply; + + return HDF_SUCCESS; +} + +int32_t BindLinearVibratorDriver(struct HdfDeviceObject *device) +{ + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(device, HDF_FAILURE); + + struct VibratorLinearDriverData *drvData = (struct VibratorLinearDriverData *)OsalMemCalloc(sizeof(*drvData)); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_MALLOC_FAIL); + + drvData->ioService.Dispatch = DispatchLinearVibrator; + drvData->device = device; + device->service = &drvData->ioService; + g_linearVibratorData = drvData; + + return HDF_SUCCESS; +} + +static int32_t ParserLinearConfig(const struct DeviceResourceNode *node, struct VibratorLinearDriverData *drvData) +{ + int32_t ret; + struct DeviceResourceIface *parser = NULL; + + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(node, HDF_FAILURE); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(drvData, HDF_FAILURE); + + parser = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(parser, HDF_ERR_INVALID_PARAM); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(parser->GetChildNode, HDF_ERR_INVALID_PARAM); + + const struct DeviceResourceNode *configNode = parser->GetChildNode(node, "vibratorChipConfig"); + ret = parser->GetUint32(configNode, "busType", &drvData->busType, 0); + CHECK_VIBRATOR_PARSER_RESULT_RETURN_VALUE(ret, "busType"); + if (drvData->busType == VIBRATOR_BUS_GPIO) { + ret = parser->GetUint32(configNode, "gpioNum", &drvData->gpioNum, 0); + CHECK_VIBRATOR_PARSER_RESULT_RETURN_VALUE(ret, "gpioNum"); + } + + ret = parser->GetUint32(configNode, "startReg", &drvData->startReg, 0); + CHECK_VIBRATOR_PARSER_RESULT_RETURN_VALUE(ret, "startReg"); + ret = parser->GetUint32(configNode, "stopReg", &drvData->stopReg, 0); + CHECK_VIBRATOR_PARSER_RESULT_RETURN_VALUE(ret, "stopReg"); + ret = parser->GetUint32(configNode, "startMask", &drvData->mask, 0); + CHECK_VIBRATOR_PARSER_RESULT_RETURN_VALUE(ret, "startMask"); + + return HDF_SUCCESS; +} + +int32_t InitLinearVibratorDriver(struct HdfDeviceObject *device) +{ + static struct VibratorOps ops; + + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(device, HDF_FAILURE); + + struct VibratorLinearDriverData *drvData = (struct VibratorLinearDriverData *)device->service; + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(drvData, HDF_FAILURE); + + ops.Start = StartLinearVibrator; + ops.StartEffect = StartEffectLinearVibrator; + ops.Stop = StopLinearVibrator; + + if (RegisterVibrator(&ops) != HDF_SUCCESS) { + HDF_LOGE("%s: register vibrator ops fail", __func__); + return HDF_FAILURE; + } + + if (ParserLinearConfig(device->property, drvData) != HDF_SUCCESS) { + HDF_LOGE("%s: parser vibrator cfg fail", __func__); + return HDF_FAILURE; + } + + if (GpioSetDir(drvData->gpioNum, GPIO_DIR_OUT) != HDF_SUCCESS) { + HDF_LOGE("%s: set vibrator gpio fail", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +void ReleaseLinearVibratorDriver(struct HdfDeviceObject *device) +{ + struct VibratorLinearDriverData *drvData = (struct VibratorLinearDriverData *)device->service; + if (device == NULL || drvData == NULL) { + HDF_LOGE("%s: pointer is null and return errno", __func__); + return; + } + + (void)OsalMemFree(drvData); + g_linearVibratorData = NULL; +} + +struct HdfDriverEntry g_linearVibratorDriverEntry = { + .moduleVersion = 1, + .moduleName = "HDF_LINEAR_VIBRATOR", + .Bind = BindLinearVibratorDriver, + .Init = InitLinearVibratorDriver, + .Release = ReleaseLinearVibratorDriver, +}; + +HDF_INIT(g_linearVibratorDriverEntry); diff --git a/model/misc/vibrator/driver/chipset/vibrator_linear_driver.h b/model/misc/vibrator/driver/chipset/vibrator_linear_driver.h new file mode 100644 index 000000000..6c194f1c2 --- /dev/null +++ b/model/misc/vibrator/driver/chipset/vibrator_linear_driver.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#ifndef VIBRATOR_LINEAR_DRIVER_H +#define VIBRATOR_LINEAR_DRIVER_H + +#include "hdf_device_desc.h" + +struct VibratorLinearDriverData { + struct IDeviceIoService ioService; + struct HdfDeviceObject *device; + uint32_t busType; + uint32_t gpioNum; + uint32_t startReg; + uint32_t stopReg; + uint32_t mask; +}; + +#endif /* VIBRATOR_LINEAR_DRIVER_H */ diff --git a/model/misc/vibrator/driver/include/vibrator_driver.h b/model/misc/vibrator/driver/include/vibrator_driver.h new file mode 100644 index 000000000..d4114f797 --- /dev/null +++ b/model/misc/vibrator/driver/include/vibrator_driver.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#ifndef VIBRATOR_DRIVER_H +#define VIBRATOR_DRIVER_H + +#include "osal_mutex.h" +#include "hdf_device_desc.h" +#include "hdf_workqueue.h" +#include "vibrator_driver_type.h" + +struct VibratorOps { + int32_t (*Start)(void); + int32_t (*StartEffect)(uint32_t effectType); + int32_t (*Stop)(void); +}; + +typedef int32_t (*VibratorCmdHandle)(struct HdfSBuf *reqData, struct HdfSBuf *reply); + +struct VibratorCmdHandleList { + int32_t cmd; + VibratorCmdHandle func; +}; + +struct VibratorDriverData { + struct IDeviceIoService ioService; + struct HdfDeviceObject *device; + HdfWorkQueue workQueue; + HdfWork work; + struct OsalMutex mutex; + enum VibratorConfigMode mode; + enum VibratorState state; + struct VibratorOps ops; +}; + +void StartTimeVibrator(void); +void StopVibrator(void); +void SetEffectVibrator(uint32_t type); +int32_t RegisterVibrator(struct VibratorOps *ops); + +#endif /* VIBRATOR_DRIVER_H */ diff --git a/model/misc/vibrator/driver/include/vibrator_driver_type.h b/model/misc/vibrator/driver/include/vibrator_driver_type.h new file mode 100644 index 000000000..e6dbae303 --- /dev/null +++ b/model/misc/vibrator/driver/include/vibrator_driver_type.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#ifndef VIBRATOR_DRIVER_TYPE_H +#define VIBRATOR_DRIVER_TYPE_H + +#include "hdf_log.h" + +#define CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(ptr, ret) do { \ + if ((ptr) == NULL) { \ + HDF_LOGE("%s:line %d pointer is null and return errno", __func__, __LINE__); \ + return (ret); \ + } \ +} while (0) + +#define CHECK_VIBRATOR_PARSER_RESULT_RETURN_VALUE(ret, str) do { \ + if (ret != HDF_SUCCESS) { \ + HDF_LOGE("%s:line %d %s fail, ret = %d!", __func__, __LINE__, str, ret); \ + return HDF_FAILURE; \ + } \ +} while (0) + +#define CHECK_VIBRATOR_NULL_PTR_RETURN(ptr) do { \ + if ((ptr) == NULL) { \ + HDF_LOGE("%s:line %d pointer is null and return", __func__, __LINE__); \ + return; \ + } \ +} while (0) + +enum VibratorBusType { + VIBRATOR_BUS_I2C = 0, + VIBRATOR_BUS_GPIO = 1, +}; + +enum VibratorState { + VIBRATOR_STATE_IDLE = 0, + VIBRATOR_STATE_START_TIMER = 1, + VIBRATOR_STATE_STOP = 2, + VIBRATOR_STATE_SET_EFFECT = 3, +}; + +enum VibratorConfigMode { + VIBRATOR_MODE_ONCE = 0, // The mode of a one-shot vibration effect. + VIBRATOR_MODE_PRESET = 1, // The mode of a preset vibration effect. + VIBRATOR_MODE_BUTT = 0XFF, +}; + +enum VibratorDrvIoCmd { + VIBRATOR_DRV_IO_START_ONCE = 0, + VIBRATOR_DRV_IO_START_PRESET = 1, + VIBRATOR_DRV_IO_STOP = 2, + VIBRATOR_DRV_IO_END, +}; + +#endif /* VIBRATOR_DRIVER_TYPE_H */ diff --git a/model/misc/vibrator/driver/include/vibrator_haptic.h b/model/misc/vibrator/driver/include/vibrator_haptic.h new file mode 100644 index 000000000..c6f4b1062 --- /dev/null +++ b/model/misc/vibrator/driver/include/vibrator_haptic.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#ifndef VIBRATOR_HAPTIC_H +#define VIBRATOR_HAPTIC_H + +#include "hdf_device_desc.h" +#include "hdf_dlist.h" +#include "osal_mutex.h" +#include "osal_timer.h" +#include "vibrator_driver_type.h" + +#define VIBRATOR_MAX_HAPTIC_SEQ 1024 +#define VIBRATOR_MIN_WAIT_TIME 50 // unit:ms + +enum VibratorEffectType { + VIBRATOR_TYPE_EFFECT = 0, // Preset effect in device + VIBRATOR_TYPE_TIME = 1, // Preset effect by time +}; + +enum VibratorTimeSeqIndex { + VIBRATOR_TIME_DELAY_INDEX = 0, + VIBRATOR_TIME_DURATION_INDEX = 1, + VIBRATOR_TIME_INDEX_BUTT, +}; + +struct VibratorEffectNode { + const char *effect; + int32_t num; + uint32_t *seq; // The first element of seq is preset type referring to enum VibratorEffectType + struct DListHead node; +}; + +struct VibratorEffectCfg { + enum VibratorConfigMode cfgMode; // References enum VibratorConfigMode + uint32_t duration; + const char *effect; +}; + +struct VibratorHapticData { + bool supportHaptic; + struct DListHead effectSeqHead; + struct OsalMutex mutex; + OsalTimer timer; + uint32_t duration[VIBRATOR_TIME_INDEX_BUTT]; + int32_t effectType; + int32_t seqCount; + uint32_t *currentEffectSeq; + int32_t currentSeqIndex; +}; + +int32_t CreateVibratorHaptic(struct HdfDeviceObject *device); +int32_t StartHaptic(struct VibratorEffectCfg *effectCfg); +int32_t StopHaptic(void); +int32_t DestroyVibratorHaptic(void); + +#endif /* VIBRATOR_HAPTIC_H */ diff --git a/model/misc/vibrator/driver/src/vibrator_driver.c b/model/misc/vibrator/driver/src/vibrator_driver.c new file mode 100644 index 000000000..9d47a1be9 --- /dev/null +++ b/model/misc/vibrator/driver/src/vibrator_driver.c @@ -0,0 +1,314 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#include "securec.h" +#include "hdf_base.h" +#include "hdf_device_desc.h" +#include "osal_mem.h" +#include "vibrator_driver.h" +#include "vibrator_haptic.h" + +#define HDF_LOG_TAG vibrator_driver_c + +#define VIBRATOR_WORK_QUEUE_NAME "vibrator_queue" +#define VIBRATOR_START_TIME 10 + +struct VibratorDriverData *g_vibratorDrvData = NULL; + +static struct VibratorDriverData *GetVibratorDrvData(void) +{ + return g_vibratorDrvData; +} + +int32_t RegisterVibrator(struct VibratorOps *ops) +{ + struct VibratorDriverData *drvData = GetVibratorDrvData(); + + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(ops, HDF_FAILURE); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(drvData, HDF_FAILURE); + + (void)OsalMutexLock(&drvData->mutex); + drvData->ops.Start = ops->Start; + drvData->ops.StartEffect = ops->StartEffect; + drvData->ops.Stop = ops->Stop; + (void)OsalMutexUnlock(&drvData->mutex); + + return HDF_SUCCESS; +} + +void StartTimeVibrator() +{ + struct VibratorDriverData *drvData = GetVibratorDrvData(); + + CHECK_VIBRATOR_NULL_PTR_RETURN(drvData); + + drvData->state = VIBRATOR_STATE_START_TIMER; + HdfAddWork(&drvData->workQueue, &drvData->work); +} + +void StopVibrator() +{ + struct VibratorDriverData *drvData = GetVibratorDrvData(); + + CHECK_VIBRATOR_NULL_PTR_RETURN(drvData); + + drvData->state = VIBRATOR_STATE_STOP; + HdfAddWork(&drvData->workQueue, &drvData->work); +} + +void SetEffectVibrator(uint32_t type) +{ + int32_t ret; + struct VibratorDriverData *drvData = GetVibratorDrvData(); + + CHECK_VIBRATOR_NULL_PTR_RETURN(drvData); + CHECK_VIBRATOR_NULL_PTR_RETURN(drvData->ops.StartEffect); + + ret = drvData->ops.StartEffect(type); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: start effect fail", __func__); + return; + } + + drvData->state = VIBRATOR_STATE_SET_EFFECT; +} + +static void VibratorWorkEntry(void *para) +{ + int32_t ret = HDF_FAILURE; + struct VibratorDriverData *drvData = (struct VibratorDriverData *)para; + + CHECK_VIBRATOR_NULL_PTR_RETURN(drvData); + CHECK_VIBRATOR_NULL_PTR_RETURN(drvData->ops.Start); + CHECK_VIBRATOR_NULL_PTR_RETURN(drvData->ops.Stop); + + if (drvData->state == VIBRATOR_STATE_START_TIMER) { + ret = drvData->ops.Start(); + } + + if (drvData->state == VIBRATOR_STATE_STOP) { + ret = drvData->ops.Stop(); + } + + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: add vibrator work fail! device state[%d]!", __func__, drvData->state); + } +} + +static int32_t StartOnce(struct HdfSBuf *data, struct HdfSBuf *reply) +{ + uint32_t duration; + int32_t ret; + struct VibratorEffectCfg config; + struct VibratorDriverData *drvData = GetVibratorDrvData(); + (void)reply; + + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(data, HDF_FAILURE); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(drvData, HDF_FAILURE); + + if (!HdfSbufReadUint32(data, &duration)) { + HDF_LOGE("%s: sbuf read duration failed", __func__); + return HDF_FAILURE; + } + + if (duration == 0) { + HDF_LOGE("%s: vibrator duration invalid para", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (drvData->mode != VIBRATOR_MODE_BUTT) { + HDF_LOGI("%s: vibrater haptic is busy now, please stop first!", __func__); + return HDF_ERR_DEVICE_BUSY; + } + + (void)OsalMutexLock(&drvData->mutex); + drvData->mode = VIBRATOR_MODE_ONCE; + (void)OsalMutexUnlock(&drvData->mutex); + + // start once time vibrate + config.cfgMode = VIBRATOR_MODE_ONCE; + config.duration = duration; + config.effect = NULL; + + ret = StartHaptic(&config); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: start haptic fail!", __func__); + return ret; + } + + return HDF_SUCCESS; +} + +static int32_t StartEffect(struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t ret; + const char *effect = NULL; + struct VibratorEffectCfg config; + struct VibratorDriverData *drvData = GetVibratorDrvData(); + (void)reply; + + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(data, HDF_FAILURE); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(drvData, HDF_FAILURE); + + effect = HdfSbufReadString(data); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(effect, HDF_FAILURE); + + if (drvData->mode != VIBRATOR_MODE_BUTT) { + HDF_LOGI("%s: vibrater haptic is busy now, please stop first!", __func__); + return HDF_ERR_DEVICE_BUSY; + } + + (void)OsalMutexLock(&drvData->mutex); + drvData->mode = VIBRATOR_MODE_PRESET; + (void)OsalMutexUnlock(&drvData->mutex); + + // start once time vibrate + config.cfgMode = VIBRATOR_MODE_PRESET; + config.duration = 0; + config.effect = effect; + + ret = StartHaptic(&config); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: start haptic fail!", __func__); + return ret; + } + + return HDF_SUCCESS; +} + +static int32_t Stop(struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t ret; + int32_t mode; + struct VibratorDriverData *drvData = GetVibratorDrvData(); + (void)reply; + + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(data, HDF_FAILURE); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(drvData, HDF_FAILURE); + + if (!HdfSbufReadInt32(data, &mode)) { + HDF_LOGE("%s: sbuf read mode failed", __func__); + return HDF_FAILURE; + } + + if ((mode != VIBRATOR_MODE_ONCE) && (mode != VIBRATOR_MODE_PRESET)) { + HDF_LOGE("%s: vibrator stop mode failed", __func__); + return HDF_FAILURE; + } + + if (drvData->mode == VIBRATOR_MODE_BUTT) { + HDF_LOGD("%s: vibrater haptic had stopped", __func__); + return HDF_SUCCESS; + } + + ret = StopHaptic(); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: stop haptic fail!", __func__); + return ret; + } + + (void)OsalMutexLock(&drvData->mutex); + drvData->mode = VIBRATOR_MODE_BUTT; + (void)OsalMutexUnlock(&drvData->mutex); + + return HDF_SUCCESS; +} + +static struct VibratorCmdHandleList g_vibratorCmdHandle[] = { + {VIBRATOR_DRV_IO_START_ONCE, StartOnce}, + {VIBRATOR_DRV_IO_START_PRESET, StartEffect}, + {VIBRATOR_DRV_IO_STOP, Stop}, +}; + +static int32_t DispatchVibrator(struct HdfDeviceIoClient *client, + int32_t cmd, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t loop; + + for (loop = 0; loop < sizeof(g_vibratorCmdHandle) / sizeof(g_vibratorCmdHandle[0]); ++loop) { + if ((cmd == g_vibratorCmdHandle[loop].cmd) && (g_vibratorCmdHandle[loop].func != NULL)) { + return g_vibratorCmdHandle[loop].func(data, reply); + } + } + + return HDF_SUCCESS; +} + +int32_t BindVibratorDriver(struct HdfDeviceObject *device) +{ + struct VibratorDriverData *drvData = NULL; + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(device, HDF_FAILURE); + + drvData = (struct VibratorDriverData *)OsalMemCalloc(sizeof(*drvData)); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_MALLOC_FAIL); + + drvData->ioService.Dispatch = DispatchVibrator; + drvData->device = device; + device->service = &drvData->ioService; + g_vibratorDrvData = drvData; + + return HDF_SUCCESS; +} + +int32_t InitVibratorDriver(struct HdfDeviceObject *device) +{ + struct VibratorDriverData *drvData = NULL; + + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(device, HDF_FAILURE); + drvData = (struct VibratorDriverData *)device->service; + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(drvData, HDF_FAILURE); + + drvData->mode = VIBRATOR_MODE_BUTT; + drvData->state = VIBRATOR_STATE_IDLE; + + if (OsalMutexInit(&drvData->mutex) != HDF_SUCCESS) { + HDF_LOGE("%s: init mutex fail!", __func__); + return HDF_FAILURE; + } + + if (HdfWorkQueueInit(&drvData->workQueue, VIBRATOR_WORK_QUEUE_NAME) != HDF_SUCCESS) { + HDF_LOGE("%s: init workQueue fail!", __func__); + return HDF_FAILURE; + } + + if (HdfWorkInit(&drvData->work, VibratorWorkEntry, (void*)drvData) != HDF_SUCCESS) { + HDF_LOGE("%s: init workQueue fail!", __func__); + return HDF_FAILURE; + } + + if (CreateVibratorHaptic(device) != HDF_SUCCESS) { + HDF_LOGE("%s: init workQueue fail!", __func__); + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +void ReleaseVibratorDriver(struct HdfDeviceObject *device) +{ + struct VibratorDriverData *drvData = (struct VibratorDriverData *)device->service; + if (device == NULL || drvData == NULL) { + HDF_LOGE("%s: pointer is null and return errno", __func__); + return; + } + + (void)DestroyVibratorHaptic(); + (void)OsalMutexDestroy(&drvData->mutex); + (void)OsalMemFree(drvData); + g_vibratorDrvData = NULL; +} + +struct HdfDriverEntry g_vibratorDriverEntry = { + .moduleVersion = 1, + .moduleName = "HDF_VIBRATOR", + .Bind = BindVibratorDriver, + .Init = InitVibratorDriver, + .Release = ReleaseVibratorDriver, +}; + +HDF_INIT(g_vibratorDriverEntry); diff --git a/model/misc/vibrator/driver/src/vibrator_haptic.c b/model/misc/vibrator/driver/src/vibrator_haptic.c new file mode 100644 index 000000000..740162196 --- /dev/null +++ b/model/misc/vibrator/driver/src/vibrator_haptic.c @@ -0,0 +1,396 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#include "securec.h" +#include "device_resource_if.h" +#include "hdf_base.h" +#include "hdf_device_desc.h" +#include "osal_mem.h" +#include "vibrator_driver.h" +#include "vibrator_haptic.h" + +#define HDF_LOG_TAG vibrator_haptic_c +#define VIBRATOR_HAPTIC_STACK_SIZE 0x4000 +#define VIBRATOR_HAPTIC_SEQ_MAX 1024 +#define VIBRATOR_HAPTIC_SEQ_SIZE 4 +#define VIBRATOR_HAPTIC_SEQ_NAME_MAX 48 +#define VIBRATOR_HAPTIC_SEQ_SIZE_MAX (4 * VIBRATOR_HAPTIC_SEQ_MAX) + +struct VibratorHapticData *g_vibratorHapticData = NULL; + +static struct VibratorHapticData *GetHapticData(void) +{ + return g_vibratorHapticData; +} + +static struct VibratorEffectNode *MallocEffectNode(int32_t seqSize) +{ + uint32_t *seq = NULL; + struct VibratorEffectNode *node = NULL; + + if (seqSize <= 0 || seqSize > VIBRATOR_HAPTIC_SEQ_SIZE_MAX) { + HDF_LOGE("%s: malloc ", __func__); + return NULL; + } + + seq = (uint32_t *)OsalMemCalloc(seqSize); + if (seq == NULL) { + HDF_LOGE("%s: malloc seq fail", __func__); + return NULL; + } + + node = (struct VibratorEffectNode *)OsalMemCalloc(sizeof(*node)); + if (node == NULL) { + HDF_LOGE("%s: malloc seq fail", __func__); + OsalMemFree(seq); + return NULL; + } + node->seq = seq; + + return node; +} + +static int32_t ParserHapticEffect(struct DeviceResourceIface *parser, const struct DeviceResourceNode *hapticNode) +{ + int32_t ret; + int32_t count; + struct VibratorEffectNode *effectNode = NULL; + const struct DeviceResourceAttr *hapticAttr = NULL; + struct VibratorHapticData *hapticData = GetHapticData(); + + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(hapticData, HDF_FAILURE); + + (void)OsalMutexLock(&hapticData->mutex); + DEV_RES_NODE_FOR_EACH_ATTR(hapticNode, hapticAttr) { + if ((hapticAttr == NULL) || (hapticAttr->name == NULL)) { + break; + } + + count = parser->GetElemNum(hapticNode, hapticAttr->name); + // Minimum of two elements, including the type and sequence. + if (count <= 1 || count > VIBRATOR_HAPTIC_SEQ_MAX) { + HDF_LOGD("%s: haptic [%s] parser seq count fail", __func__, hapticAttr->name); + continue; + } + + effectNode = MallocEffectNode(count * VIBRATOR_HAPTIC_SEQ_SIZE); + if (effectNode == NULL) { + HDF_LOGD("%s: malloc effect effectNode fail", __func__); + continue; + } + effectNode->effect = hapticAttr->name; + ret = parser->GetUint32Array(hapticNode, hapticAttr->name, effectNode->seq, count, 0); + CHECK_VIBRATOR_PARSER_RESULT_RETURN_VALUE(ret, hapticAttr->name); + effectNode->num = count; + DListInsertTail(&effectNode->node, &hapticData->effectSeqHead); + } + (void)OsalMutexUnlock(&hapticData->mutex); + + if (DListIsEmpty(&hapticData->effectSeqHead)) { + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +static int32_t ParserVibratorHapticConfig(const struct DeviceResourceNode *node) +{ + bool supportPresetFlag = false; + struct DeviceResourceIface *parser = NULL; + const struct DeviceResourceNode *vibratorAttrNode = NULL; + const struct DeviceResourceNode *vibratorHapticNode = NULL; + struct VibratorHapticData *hapticData = GetHapticData(); + + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(hapticData, HDF_FAILURE); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(node, HDF_ERR_INVALID_PARAM); + + parser = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(parser, HDF_ERR_INVALID_PARAM); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(parser->GetChildNode, HDF_ERR_INVALID_PARAM); + + // get haptic type + vibratorAttrNode = parser->GetChildNode(node, "vibratorAttr"); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(vibratorAttrNode, HDF_ERR_INVALID_PARAM); + supportPresetFlag = parser->GetBool(vibratorAttrNode, "supportPreset"); + + (void)OsalMutexLock(&hapticData->mutex); + hapticData->supportHaptic = supportPresetFlag; + (void)OsalMutexUnlock(&hapticData->mutex); + + if (!supportPresetFlag) { + HDF_LOGD("%s: vibrator not support effect", __func__); + return HDF_SUCCESS; + } + + // malloc haptic resource + vibratorHapticNode = parser->GetChildNode(node, "vibratorHapticConfig"); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(vibratorHapticNode, HDF_ERR_INVALID_PARAM); + if (ParserHapticEffect(parser, vibratorHapticNode) != HDF_SUCCESS) { + HDF_LOGE("%s: vibrator get effect fail", __func__); + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +static uint32_t ProcessHapticTime(struct VibratorHapticData *hapticData) +{ + uint32_t duration; + + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(hapticData, HDF_FAILURE); + if ((hapticData->currentSeqIndex < 0) || (hapticData->currentSeqIndex >= hapticData->seqCount)) { + return 0; + } + + if (hapticData->currentSeqIndex % 2 == 0) { + StartTimeVibrator(); + } else { + StopVibrator(); + } + + hapticData->currentSeqIndex++; + if (hapticData->currentSeqIndex >= hapticData->seqCount) { + return 0; + } + + duration = hapticData->currentEffectSeq[hapticData->currentSeqIndex] == 0 ? + VIBRATOR_MIN_WAIT_TIME : hapticData->currentEffectSeq[hapticData->currentSeqIndex]; + return duration; +} + +static uint32_t ProcessHapticEffect(struct VibratorHapticData *hapticData) +{ + uint32_t effect; + uint32_t duration; + + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(hapticData, HDF_FAILURE); + + if ((hapticData->currentSeqIndex < 0) || ((hapticData->currentSeqIndex + 1) >= hapticData->seqCount)) { + HDF_LOGE("%{s: seq index invalid para", __func__); + return 0; + } + + hapticData->currentSeqIndex++; + effect = hapticData->currentEffectSeq[hapticData->currentSeqIndex]; + SetEffectVibrator(effect); + + hapticData->currentSeqIndex++; + if (hapticData->currentSeqIndex >= hapticData->seqCount) { + HDF_LOGE("%s: seq index exceed max value", __func__); + return 0; + } + + duration = hapticData->currentEffectSeq[hapticData->currentSeqIndex] == 0 ? + VIBRATOR_MIN_WAIT_TIME : hapticData->currentEffectSeq[hapticData->currentSeqIndex]; + return duration; +} + +void HapticTimerEntry(uintptr_t para) +{ + int32_t ret; + struct VibratorHapticData *hapticData = NULL; + uint32_t duration; + + hapticData = (struct VibratorHapticData *)para; + CHECK_VIBRATOR_NULL_PTR_RETURN(hapticData); + + if (hapticData->effectType == VIBRATOR_TYPE_TIME) { + duration = ProcessHapticTime(hapticData); + HDF_LOGE("%s:ProcessHapticTime duration[%d]", __func__, duration); + } + + if (hapticData->effectType == VIBRATOR_TYPE_EFFECT) { + duration = ProcessHapticEffect(hapticData); + HDF_LOGE("%s:ProcessHapticEffect duration[%d]", __func__, duration); + } + + duration = ((duration > 0) && (duration < VIBRATOR_MIN_WAIT_TIME)) ? VIBRATOR_MIN_WAIT_TIME : duration; + if ((duration > 0) && (OsalTimerSetTimeout(&hapticData->timer, duration) == HDF_SUCCESS)) { + HDF_LOGD("%s: modify haptic timer duration[%d]", __func__, duration); + return; + } + + if (hapticData->timer.realTimer != NULL) { + ret = OsalTimerDelete(&hapticData->timer); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: delete haptic timer fail!", __func__); + } + } + + return; +} + +static int32_t GetHapticSeqByEffect(struct VibratorEffectCfg *effectCfg) +{ + struct VibratorHapticData *hapticData = NULL; + struct VibratorEffectNode *pos = NULL; + struct VibratorEffectNode *tmp = NULL; + + hapticData = GetHapticData(); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(hapticData, HDF_FAILURE); + + (void)OsalMutexLock(&hapticData->mutex); + hapticData->seqCount = 0; + hapticData->currentEffectSeq = NULL; + hapticData->currentSeqIndex = 0; + + if (effectCfg->cfgMode == VIBRATOR_MODE_ONCE) { + hapticData->duration[VIBRATOR_TIME_DELAY_INDEX] = VIBRATOR_MIN_WAIT_TIME; + hapticData->duration[VIBRATOR_TIME_DURATION_INDEX] = effectCfg->duration; + hapticData->effectType = VIBRATOR_TYPE_TIME; + hapticData->seqCount = VIBRATOR_TIME_INDEX_BUTT; + hapticData->currentEffectSeq = &hapticData->duration[VIBRATOR_TIME_DELAY_INDEX]; + (void)OsalMutexUnlock(&hapticData->mutex); + return HDF_SUCCESS; + } + + if ((effectCfg->cfgMode == VIBRATOR_MODE_PRESET) && (effectCfg->effect != NULL)) { + DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, &hapticData->effectSeqHead, struct VibratorEffectNode, node) { + if (strcmp(effectCfg->effect, pos->effect) == 0 && pos->seq != NULL) { + hapticData->effectType = pos->seq[0]; + hapticData->seqCount = pos->num - 1; + hapticData->currentEffectSeq = &(pos->seq[1]); + break; + } + } + if ((hapticData->seqCount <= 1) || (hapticData->seqCount > VIBRATOR_MAX_HAPTIC_SEQ)) { + HDF_LOGE("%s: not find effect type!", __func__); + (void)OsalMutexUnlock(&hapticData->mutex); + return HDF_ERR_INVALID_PARAM; + } + (void)OsalMutexUnlock(&hapticData->mutex); + return HDF_SUCCESS; + } + + HDF_LOGE("%s: not support effect type!", __func__); + (void)OsalMutexUnlock(&hapticData->mutex); + return HDF_ERR_NOT_SUPPORT; +} + +int32_t StartHaptic(struct VibratorEffectCfg *effectCfg) +{ + int32_t ret; + uint32_t duration; + struct VibratorHapticData *hapticData = GetHapticData(); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(effectCfg, HDF_FAILURE); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(hapticData, HDF_FAILURE); + + if ((effectCfg->cfgMode == VIBRATOR_MODE_PRESET) && (!hapticData->supportHaptic)) { + HDF_LOGE("%s: vibrator no support haptic!", __func__); + return HDF_ERR_NOT_SUPPORT; + } + + ret = GetHapticSeqByEffect(effectCfg); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: get haptic seq fail!", __func__); + return ret; + } + + duration = hapticData->currentEffectSeq[0] < VIBRATOR_MIN_WAIT_TIME ? + VIBRATOR_MIN_WAIT_TIME : hapticData->currentEffectSeq[0]; + + if (OsalTimerCreate(&hapticData->timer, duration, HapticTimerEntry, (uintptr_t)hapticData) != HDF_SUCCESS) { + HDF_LOGE("%s: create vibrator timer fail!", __func__); + return HDF_FAILURE; + } + + if (OsalTimerStartLoop(&hapticData->timer) != HDF_SUCCESS) { + HDF_LOGE("%s: start vibrator timer fail!", __func__); + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +int32_t StopHaptic() +{ + int32_t ret; + struct VibratorHapticData *hapticData = GetHapticData(); + + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(hapticData, HDF_FAILURE); + + if (hapticData->timer.realTimer != NULL) { + HDF_LOGE("%s: delete vibrator Timer!", __func__); + (void)OsalMutexLock(&hapticData->mutex); + ret = OsalTimerDelete(&hapticData->timer); + (void)OsalMutexUnlock(&hapticData->mutex); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: delete vibrator timer fail!", __func__); + return ret; + } + } + + StopVibrator(); + return HDF_SUCCESS; +} + +int32_t CreateVibratorHaptic(struct HdfDeviceObject *device) +{ + struct VibratorHapticData *hapticData = NULL; + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(device, HDF_FAILURE); + + hapticData = (struct VibratorHapticData *)OsalMemCalloc(sizeof(*hapticData)); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(hapticData, HDF_ERR_MALLOC_FAIL); + g_vibratorHapticData = hapticData; + hapticData->supportHaptic = false; + + if (OsalMutexInit(&hapticData->mutex) != HDF_SUCCESS) { + HDF_LOGE("%s: fail to init mutex", __func__); + goto EXIT; + } + + DListHeadInit(&hapticData->effectSeqHead); + + // get haptic hcs + if (ParserVibratorHapticConfig(device->property) != HDF_SUCCESS) { + HDF_LOGE("%s: parser haptic config fail!", __func__); + goto EXIT; + } + + return HDF_SUCCESS; +EXIT: + OsalMemFree(hapticData); + return HDF_FAILURE; +} + +static void FreeHapticConfig() +{ + struct VibratorHapticData *hapticData = GetHapticData(); + struct VibratorEffectNode *pos = NULL; + struct VibratorEffectNode *tmp = NULL; + + if (hapticData == NULL) { + return; + } + + (void)OsalMutexLock(&hapticData->mutex); + DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, &hapticData->effectSeqHead, struct VibratorEffectNode, node) { + if (pos->seq != NULL) { + OsalMemFree(pos->seq); + pos->seq = NULL; + } + pos->effect = NULL; + DListRemove(&pos->node); + OsalMemFree(pos); + } + (void)OsalMutexUnlock(&hapticData->mutex); +} + +int32_t DestroyVibratorHaptic() +{ + struct VibratorHapticData *hapticData = GetHapticData(); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(hapticData, HDF_FAILURE); + + if (hapticData->supportHaptic) { + FreeHapticConfig(); + } + + (void)OsalMutexDestroy(&hapticData->mutex); + + return HDF_SUCCESS; +} -- Gitee From caf655e82491962d5bcf64799238c5105c7144d5 Mon Sep 17 00:00:00 2001 From: kevin Date: Thu, 1 Jul 2021 19:22:06 +0800 Subject: [PATCH 2/2] fixbug vibrator Signed-off-by: kevin --- model/misc/vibrator/driver/src/vibrator_haptic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/misc/vibrator/driver/src/vibrator_haptic.c b/model/misc/vibrator/driver/src/vibrator_haptic.c index 740162196..39eacb6f3 100644 --- a/model/misc/vibrator/driver/src/vibrator_haptic.c +++ b/model/misc/vibrator/driver/src/vibrator_haptic.c @@ -171,7 +171,7 @@ static uint32_t ProcessHapticEffect(struct VibratorHapticData *hapticData) CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(hapticData, HDF_FAILURE); if ((hapticData->currentSeqIndex < 0) || ((hapticData->currentSeqIndex + 1) >= hapticData->seqCount)) { - HDF_LOGE("%{s: seq index invalid para", __func__); + HDF_LOGE("%s: seq index invalid para", __func__); return 0; } -- Gitee