From ba95f1372543ce77e8a9c93298adaeeabbb30346 Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Tue, 2 Nov 2021 20:33:43 +0800 Subject: [PATCH 1/3] modify_code Signed-off-by: YOUR_NAME --- .../common/include/sensor_config_controller.h | 2 + .../common/include/sensor_config_parser.h | 1 + .../common/src/sensor_config_controller.c | 94 +++++++++++++------ 3 files changed, 70 insertions(+), 27 deletions(-) diff --git a/model/sensor/driver/common/include/sensor_config_controller.h b/model/sensor/driver/common/include/sensor_config_controller.h index 9521f7dc5..4e4c2f058 100644 --- a/model/sensor/driver/common/include/sensor_config_controller.h +++ b/model/sensor/driver/common/include/sensor_config_controller.h @@ -26,6 +26,8 @@ enum SensorOpsType { SENSOR_OPS_TYPE_WRITE = 2, SENSOR_OPS_TYPE_READ_CHECK = 3, SENSOR_OPS_TYPE_UPDATE_BITWISE = 4, + SENSOR_OPS_TYPE_EXTBUFF_READ = 5, + SENSOR_OPS_TYPE_EXTBUFF_WRITE = 6, }; struct SensorOpsCall { diff --git a/model/sensor/driver/common/include/sensor_config_parser.h b/model/sensor/driver/common/include/sensor_config_parser.h index 27ff0b1c4..ebc20e4ec 100644 --- a/model/sensor/driver/common/include/sensor_config_parser.h +++ b/model/sensor/driver/common/include/sensor_config_parser.h @@ -46,6 +46,7 @@ enum SensorRegCfgIndex { }; struct SensorRegCfg { + uint8_t *dataBuff; uint16_t regAddr; uint16_t value; uint16_t mask; diff --git a/model/sensor/driver/common/src/sensor_config_controller.c b/model/sensor/driver/common/src/sensor_config_controller.c index e2f3689dd..1a36ad9f1 100644 --- a/model/sensor/driver/common/src/sensor_config_controller.c +++ b/model/sensor/driver/common/src/sensor_config_controller.c @@ -23,7 +23,7 @@ static int32_t SensorOpsNop(struct SensorBusCfg *busCfg, struct SensorRegCfg *cf static int32_t SensorOpsRead(struct SensorBusCfg *busCfg, struct SensorRegCfg *cfgItem) { - uint16_t value = 0; + uint32_t value = 0; int32_t ret; ret = ReadSensor(busCfg, cfgItem->regAddr, (uint8_t *)&value, sizeof(value)); @@ -59,16 +59,46 @@ static int32_t SensorOpsWrite(struct SensorBusCfg *busCfg, struct SensorRegCfg * value[SENSOR_ADDR_INDEX] = cfgItem->regAddr; value[SENSOR_VALUE_INDEX] = cfgItem->value; - switch (calType) { + ret = WriteSensor(busCfg, value, sizeof(value)); + CHECK_PARSER_RESULT_RETURN_VALUE(ret, "write i2c reg"); + + return ret; +} + +static int32_t SensorBitwiseCalculate(struct SensorRegCfg *cfgItem, uint32_t *value, uint32_t valueMask) +{ + uint32_t originValue; + uint32_t mask; + uint32_t tmp; + + mask = GetSensorRegRealValueMask(cfgItem, &originValue, valueMask); + switch ((enum SensorCalculateType)cfgItem->calType) { case SENSOR_CFG_CALC_TYPE_NONE: - ret = WriteSensor(busCfg, value, sizeof(value)); break; case SENSOR_CFG_CALC_TYPE_SET: + *value &= ~mask; + *value |= (originValue & mask); + break; case SENSOR_CFG_CALC_TYPE_REVERT: + tmp = *value & (~mask); + *value = ~(*value & mask); + *value = tmp | (*value); + break; case SENSOR_CFG_CALC_TYPE_XOR: + tmp = *value & (~mask); + originValue = originValue & mask; + *value = *value & mask; + *value ^= originValue; + *value = tmp | (*value); + break; case SENSOR_CFG_CALC_TYPE_LEFT_SHIFT: + *value = *value << cfgItem->shiftNum; + break; case SENSOR_CFG_CALC_TYPE_RIGHT_SHIFT: + *value = *value >> cfgItem->shiftNum; + break; default: + HDF_LOGE("%s: unsupported cal type", __func__); break; } @@ -99,30 +129,6 @@ static int32_t SensorOpsReadCheck(struct SensorBusCfg *busCfg, struct SensorRegC return HDF_SUCCESS; } -static int32_t SensorBitwiseCalculate(struct SensorRegCfg *cfgItem, uint32_t *value, uint32_t valueMask) -{ - uint32_t originValue; - uint32_t mask; - uint32_t tmp; - - mask = GetSensorRegRealValueMask(cfgItem, &originValue, valueMask); - switch ((enum SensorCalculateType)cfgItem->calType) { - case SENSOR_CFG_CALC_TYPE_SET: - *value &= ~mask; - *value |= (originValue & mask); - break; - case SENSOR_CFG_CALC_TYPE_REVERT: - tmp = *value & (~mask); - *value = ~(*value & mask); - *value = tmp | (*value & mask); - break; - default: - HDF_LOGE("%s: unsupported cal type", __func__); - break; - } - return 0; -} - static int32_t SensorOpsUpdateBitwise(struct SensorBusCfg *busCfg, struct SensorRegCfg *cfgItem) { uint32_t value = 0; @@ -150,12 +156,46 @@ static int32_t SensorOpsUpdateBitwise(struct SensorBusCfg *busCfg, struct Sensor return HDF_SUCCESS; } +static int32_t SensorOpsExtBuffRead(struct SensorBusCfg *busCfg, struct SensorRegCfg *cfgItem) +{ + int32_t ret; + + CHECK_NULL_PTR_RETURN_VALUE(busCfg, HDF_FAILURE); + + if (busCfg->busType == SENSOR_BUS_I2C) { + ret = ReadSensor(busCfg, cfgItem->regAddr, cfgItem->dataBuff, cfgItem->len); + CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read i2c reg"); + } + + return ret; +} + +static int32_t SensorOpsExtBuffWrite(struct SensorBusCfg *busCfg, struct SensorRegCfg *cfgItem) +{ + int32_t ret = HDF_FAILURE; + uint8_t value[SENSOR_VALUE_BUTT]; + + CHECK_NULL_PTR_RETURN_VALUE(busCfg, HDF_FAILURE); + + value[SENSOR_ADDR_INDEX] = cfgItem->regAddr; + value[SENSOR_VALUE_INDEX] = cfgItem->dataBuff; + + if (busCfg->busType == SENSOR_BUS_I2C) { + ret = WriteSensor(busCfg, value, cfgItem->len); + CHECK_PARSER_RESULT_RETURN_VALUE(ret, "write i2c reg"); + } + + return ret; +} + static struct SensorOpsCall g_doOpsCall[] = { { SENSOR_OPS_TYPE_NOP, SensorOpsNop }, { SENSOR_OPS_TYPE_READ, SensorOpsRead }, { SENSOR_OPS_TYPE_WRITE, SensorOpsWrite }, { SENSOR_OPS_TYPE_READ_CHECK, SensorOpsReadCheck }, { SENSOR_OPS_TYPE_UPDATE_BITWISE, SensorOpsUpdateBitwise }, + { SENSOR_OPS_TYPE_EXTBUFF_READ, SensorOpsExtBuffRead }, + { SENSOR_OPS_TYPE_EXTBUFF_WRITE, SensorOpsExtBuffWrite }, }; int32_t SetSensorRegCfgArray(struct SensorBusCfg *busCfg, const struct SensorRegCfgGroupNode *group) -- Gitee From 784e53477d696a993c9a5e109ba686ebe7b903c1 Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Wed, 3 Nov 2021 12:37:46 +0800 Subject: [PATCH 2/3] modify_code_02 Signed-off-by: YOUR_NAME --- model/sensor/driver/common/src/sensor_config_controller.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/model/sensor/driver/common/src/sensor_config_controller.c b/model/sensor/driver/common/src/sensor_config_controller.c index 1a36ad9f1..c61c83ad7 100644 --- a/model/sensor/driver/common/src/sensor_config_controller.c +++ b/model/sensor/driver/common/src/sensor_config_controller.c @@ -52,7 +52,6 @@ static uint32_t GetSensorRegRealValueMask(struct SensorRegCfg *cfgItem, uint32_t static int32_t SensorOpsWrite(struct SensorBusCfg *busCfg, struct SensorRegCfg *cfgItem) { - uint8_t calType = cfgItem->calType; uint8_t value[SENSOR_VALUE_BUTT]; int32_t ret = HDF_FAILURE; @@ -102,7 +101,7 @@ static int32_t SensorBitwiseCalculate(struct SensorRegCfg *cfgItem, uint32_t *va break; } - return ret; + return 0; } static int32_t SensorOpsReadCheck(struct SensorBusCfg *busCfg, struct SensorRegCfg *cfgItem) @@ -178,7 +177,7 @@ static int32_t SensorOpsExtBuffWrite(struct SensorBusCfg *busCfg, struct SensorR CHECK_NULL_PTR_RETURN_VALUE(busCfg, HDF_FAILURE); value[SENSOR_ADDR_INDEX] = cfgItem->regAddr; - value[SENSOR_VALUE_INDEX] = cfgItem->dataBuff; + value[SENSOR_VALUE_INDEX] = *(cfgItem->dataBuff); if (busCfg->busType == SENSOR_BUS_I2C) { ret = WriteSensor(busCfg, value, cfgItem->len); -- Gitee From 8eacba7eba32a4ebe29775ddc9e331f82ad1a1ba Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Wed, 3 Nov 2021 14:20:11 +0800 Subject: [PATCH 3/3] modify_code_03 Signed-off-by: YOUR_NAME --- model/sensor/driver/common/src/sensor_config_controller.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/sensor/driver/common/src/sensor_config_controller.c b/model/sensor/driver/common/src/sensor_config_controller.c index c61c83ad7..1be1e9825 100644 --- a/model/sensor/driver/common/src/sensor_config_controller.c +++ b/model/sensor/driver/common/src/sensor_config_controller.c @@ -157,7 +157,7 @@ static int32_t SensorOpsUpdateBitwise(struct SensorBusCfg *busCfg, struct Sensor static int32_t SensorOpsExtBuffRead(struct SensorBusCfg *busCfg, struct SensorRegCfg *cfgItem) { - int32_t ret; + int32_t ret = HDF_FAILURE; CHECK_NULL_PTR_RETURN_VALUE(busCfg, HDF_FAILURE); -- Gitee