1 /*
2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3 *
4 * HDF is dual licensed: you can use it either under the terms of
5 * the GPL, or the BSD license, at your option.
6 * See the LICENSE file in the root of this repository for complete details.
7 */
8
9 #include "sensor_config_parser.h"
10 #include <securec.h>
11 #include "device_resource_if.h"
12 #include "osal_mem.h"
13 #include "sensor_platform_if.h"
14
15 #define HDF_LOG_TAG hdf_sensor_commom
16
17 static char *g_sensorRegGroupName[SENSOR_GROUP_MAX] = {
18 "initSeqConfig",
19 "enableSeqConfig",
20 "disableSeqConfig",
21 };
22
GetSensorRegGroupNameIndex(const char * name)23 static uint32_t GetSensorRegGroupNameIndex(const char *name)
24 {
25 uint32_t index;
26
27 if (name == NULL) {
28 return SENSOR_GROUP_MAX;
29 }
30
31 for (index = 0; index < SENSOR_GROUP_MAX; ++index) {
32 if ((g_sensorRegGroupName[index] != NULL) && (strcmp(name, g_sensorRegGroupName[index]) == 0)) {
33 break;
34 }
35 }
36
37 return index;
38 }
39
ReleaseSensorAllRegConfig(struct SensorCfgData * config)40 void ReleaseSensorAllRegConfig(struct SensorCfgData *config)
41 {
42 int32_t index;
43
44 if (config == NULL || config->regCfgGroup == NULL) {
45 return;
46 }
47
48 for (index = 0; index < SENSOR_GROUP_MAX; ++index) {
49 if (config->regCfgGroup[index] != NULL) {
50 if (config->regCfgGroup[index]->regCfgItem != NULL) {
51 OsalMemFree(config->regCfgGroup[index]->regCfgItem);
52 config->regCfgGroup[index]->regCfgItem = NULL;
53 }
54 OsalMemFree(config->regCfgGroup[index]);
55 config->regCfgGroup[index] = NULL;
56 }
57 }
58 }
59
ParseSensorRegItem(struct DeviceResourceIface * parser,const struct DeviceResourceNode * regNode,const char * groupName,struct SensorRegCfgGroupNode * group)60 static int32_t ParseSensorRegItem(struct DeviceResourceIface *parser, const struct DeviceResourceNode *regNode,
61 const char *groupName, struct SensorRegCfgGroupNode *group)
62 {
63 int32_t ret;
64 int32_t step;
65 uint32_t index;
66 int32_t num;
67 uint32_t itemNum = group->itemNum;
68 uint16_t *buf = NULL;
69
70 CHECK_NULL_PTR_RETURN_VALUE(group->regCfgItem, HDF_ERR_INVALID_PARAM);
71 CHECK_NULL_PTR_RETURN_VALUE(groupName, HDF_ERR_INVALID_PARAM);
72
73 num = parser->GetElemNum(regNode, groupName);
74 if (num <= 0 || num > SENSOR_CONFIG_MAX_ITEM) {
75 HDF_LOGE("%s: parser %s element num failed", __func__, groupName);
76 return HDF_SUCCESS;
77 }
78
79 buf = (uint16_t *)OsalMemCalloc(sizeof(uint16_t) * num);
80 CHECK_NULL_PTR_RETURN_VALUE(buf, HDF_ERR_MALLOC_FAIL);
81
82 ret = parser->GetUint16Array(regNode, groupName, buf, num, 0);
83 if (ret != HDF_SUCCESS) {
84 HDF_LOGE("%s: parser %s reg array failed", __func__, groupName);
85 OsalMemFree(buf);
86 return HDF_SUCCESS;
87 }
88
89 for (index = 0; index < itemNum; ++index) {
90 step = SENSOR_REG_CFG_INDEX_MAX * index;
91 if (step + SENSOR_REG_CFG_SAVE_INDEX >= num) {
92 break;
93 }
94 group->regCfgItem[index].regAddr = buf[step + SENSOR_REG_CFG_ADDR_INDEX];
95 group->regCfgItem[index].value = buf[step + SENSOR_REG_CFG_VALUE_INDEX];
96 group->regCfgItem[index].mask = buf[step + SENSOR_REG_CFG_MASK_INDEX];
97 group->regCfgItem[index].len = buf[step + SENSOR_REG_CFG_LEN_INDEX];
98 group->regCfgItem[index].delay = buf[step + SENSOR_REG_CFG_DELAY_INDEX];
99 group->regCfgItem[index].opsType = buf[step + SENSOR_REG_CFG_OPS_INDEX];
100 group->regCfgItem[index].calType = buf[step + SENSOR_REG_CFG_CAL_INDEX];
101 group->regCfgItem[index].shiftNum = buf[step + SENSOR_REG_CFG_SHIFT_INDEX];
102 group->regCfgItem[index].debug = buf[step + SENSOR_REG_CFG_DEBUG_INDEX];
103 group->regCfgItem[index].save = buf[step + SENSOR_REG_CFG_SAVE_INDEX];
104 }
105 OsalMemFree(buf);
106
107 return HDF_SUCCESS;
108 }
109
ParseSensorRegGroup(struct DeviceResourceIface * parser,const struct DeviceResourceNode * regCfgNode,const char * groupName,struct SensorRegCfgGroupNode ** groupNode)110 int32_t ParseSensorRegGroup(struct DeviceResourceIface *parser, const struct DeviceResourceNode *regCfgNode,
111 const char *groupName, struct SensorRegCfgGroupNode **groupNode)
112 {
113 int32_t num;
114 struct SensorRegCfgGroupNode *group = NULL;
115
116 CHECK_NULL_PTR_RETURN_VALUE(parser, HDF_ERR_INVALID_PARAM);
117 CHECK_NULL_PTR_RETURN_VALUE(regCfgNode, HDF_ERR_INVALID_PARAM);
118 CHECK_NULL_PTR_RETURN_VALUE(groupName, HDF_ERR_INVALID_PARAM);
119 CHECK_NULL_PTR_RETURN_VALUE(groupNode, HDF_ERR_INVALID_PARAM);
120
121 num = parser->GetElemNum(regCfgNode, groupName);
122 group = *groupNode;
123
124 if (num > 0) {
125 if (group != NULL) {
126 if (group->regCfgItem != NULL) {
127 OsalMemFree(group->regCfgItem);
128 }
129 OsalMemFree(group);
130 }
131
132 group = (struct SensorRegCfgGroupNode*)OsalMemCalloc(sizeof(*group));
133 if (group == NULL) {
134 HDF_LOGE("%s: malloc sensor reg config group failed", __func__);
135 return HDF_ERR_MALLOC_FAIL;
136 }
137
138 *groupNode = group;
139 group->itemNum = (uint32_t)(num / SENSOR_REG_CFG_INDEX_MAX);
140 group->itemNum = ((SENSOR_REG_CFG_INDEX_MAX * group->itemNum) < (uint32_t)num) ?
141 (group->itemNum + 1) : group->itemNum;
142
143 group->regCfgItem = (struct SensorRegCfg*)OsalMemCalloc(group->itemNum * sizeof(*(group->regCfgItem)));
144 if (group->regCfgItem == NULL) {
145 HDF_LOGE("%s: malloc sensor reg config item failed", __func__);
146 return HDF_ERR_MALLOC_FAIL;
147 }
148
149 if (ParseSensorRegItem(parser, regCfgNode, groupName, group) != HDF_SUCCESS) {
150 HDF_LOGE("%s: malloc sensor reg config item data failed", __func__);
151 return HDF_FAILURE;
152 }
153 }
154
155 return HDF_SUCCESS;
156 }
157
ParseSensorRegConfig(struct SensorCfgData * config)158 int32_t ParseSensorRegConfig(struct SensorCfgData *config)
159 {
160 uint32_t index;
161 const struct DeviceResourceNode *regCfgNode = NULL;
162 struct DeviceResourceIface *parser = NULL;
163 const struct DeviceResourceAttr *regAttr = NULL;
164
165 CHECK_NULL_PTR_RETURN_VALUE(config->root, HDF_ERR_INVALID_PARAM);
166 parser = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
167 CHECK_NULL_PTR_RETURN_VALUE(parser, HDF_ERR_INVALID_PARAM);
168
169 regCfgNode = parser->GetChildNode(config->root, "sensorRegConfig");
170 CHECK_NULL_PTR_RETURN_VALUE(regCfgNode, HDF_ERR_INVALID_PARAM);
171
172 DEV_RES_NODE_FOR_EACH_ATTR(regCfgNode, regAttr) {
173 if (regAttr == NULL || regAttr->name == NULL) {
174 HDF_LOGE("%s:sensor reg node attr is null", __func__);
175 break;
176 }
177
178 index = GetSensorRegGroupNameIndex(regAttr->name);
179 if (index >= SENSOR_GROUP_MAX) {
180 HDF_LOGE("%s: get sensor register group index failed", __func__);
181 goto error;
182 }
183
184 if (ParseSensorRegGroup(parser, regCfgNode, regAttr->name, &config->regCfgGroup[index]) != HDF_SUCCESS) {
185 HDF_LOGE("%s: parse sensor register group failed", __func__);
186 goto error;
187 }
188 }
189 return HDF_SUCCESS;
190
191 error:
192 ReleaseSensorAllRegConfig(config);
193 HDF_LOGE("%s: parse sensor reg config failed", __func__);
194 return HDF_FAILURE;
195 }
196
GetSensorBusHandle(struct SensorBusCfg * busCfg)197 int32_t GetSensorBusHandle(struct SensorBusCfg *busCfg)
198 {
199 CHECK_NULL_PTR_RETURN_VALUE(busCfg, HDF_ERR_INVALID_PARAM);
200
201 if (busCfg->busType == SENSOR_BUS_I2C) {
202 uint16_t busNum = busCfg->i2cCfg.busNum;
203 busCfg->i2cCfg.handle = I2cOpen(busNum);
204 if (busCfg->i2cCfg.handle == NULL) {
205 HDF_LOGE("%s: sensor i2c Handle invalid", __func__);
206 return HDF_FAILURE;
207 }
208
209 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_SPI) || defined(CONFIG_DRIVERS_HDF_PLATFORM_SPI)
210 } else if (busCfg->busType == SENSOR_BUS_SPI) {
211 struct SpiDevInfo spiDevinfo;
212 struct SpiCfg cfg;
213 int32_t ret;
214
215 spiDevinfo.busNum = busCfg->spiCfg.busNum;
216 spiDevinfo.csNum = busCfg->spiCfg.csNum;
217 busCfg->i2cCfg.handle = SpiOpen(&spiDevinfo);
218
219 cfg.mode = SPI_CLK_PHASE | SPI_CLK_POLARITY;
220 cfg.bitsPerWord = SENSOR_DATA_WIDTH_8_BIT;
221 cfg.maxSpeedHz = SENSOR_SPI_MAX_SPEED;
222 ret = SpiSetCfg(busCfg->i2cCfg.handle, &cfg);
223 if (ret != HDF_SUCCESS) {
224 HDF_LOGE("%s: SpiSetCfg failed", __func__);
225 SpiClose(busCfg->i2cCfg.handle);
226 return ret;
227 }
228 #endif
229 }
230
231 return HDF_SUCCESS;
232 }
233
ReleaseSensorBusHandle(struct SensorBusCfg * busCfg)234 int32_t ReleaseSensorBusHandle(struct SensorBusCfg *busCfg)
235 {
236 if (busCfg == NULL) {
237 return HDF_SUCCESS;
238 }
239
240 if (busCfg->busType == SENSOR_BUS_I2C && busCfg->i2cCfg.handle != NULL) {
241 I2cClose(busCfg->i2cCfg.handle);
242 busCfg->i2cCfg.handle = NULL;
243
244 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_SPI) || defined(CONFIG_DRIVERS_HDF_PLATFORM_SPI)
245 } else if (busCfg->busType == SENSOR_BUS_SPI) {
246 SpiClose(busCfg->spiCfg.handle);
247 busCfg->spiCfg.handle = NULL;
248 #endif
249 }
250
251 return HDF_SUCCESS;
252 }
253
DetectSensorDevice(struct SensorCfgData * config)254 int32_t DetectSensorDevice(struct SensorCfgData *config)
255 {
256 uint8_t value = 0;
257 uint16_t chipIdReg;
258 uint16_t chipIdValue;
259 int32_t ret;
260
261 CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM);
262
263 chipIdReg = config->sensorAttr.chipIdReg;
264 chipIdValue = config->sensorAttr.chipIdValue;
265
266 ret = GetSensorBusHandle(&config->busCfg);
267 if (ret != HDF_SUCCESS) {
268 HDF_LOGE("%s: get sensor bus handle failed", __func__);
269 (void)ReleaseSensorBusHandle(&config->busCfg);
270 return HDF_FAILURE;
271 }
272
273 ret = ReadSensor(&config->busCfg, chipIdReg, &value, sizeof(value));
274 if (ret != HDF_SUCCESS) {
275 HDF_LOGE("%s: i2c read chip id failed", __func__);
276 (void)ReleaseSensorBusHandle(&config->busCfg);
277 return HDF_FAILURE;
278 }
279
280 if (value != chipIdValue) {
281 HDF_LOGE("%s: sensor chip[0x%x] id [0x%x] detect value[%u]", __func__, chipIdReg, chipIdValue, value);
282 (void)ReleaseSensorBusHandle(&config->busCfg);
283 return HDF_FAILURE;
284 }
285
286 HDF_LOGD("%s: sensor [%s] detect chip success", __func__, config->sensorInfo.sensorName);
287 return HDF_SUCCESS;
288 }
289
ParseSensorInfo(struct DeviceResourceIface * parser,const struct DeviceResourceNode * infoNode,struct SensorCfgData * config)290 static int32_t ParseSensorInfo(struct DeviceResourceIface *parser, const struct DeviceResourceNode *infoNode,
291 struct SensorCfgData *config)
292 {
293 int32_t ret;
294 uint16_t id;
295 int32_t value;
296 const char *name = NULL;
297
298 ret = parser->GetString(infoNode, "sensorName", &name, NULL);
299 CHECK_PARSER_RESULT_RETURN_VALUE(ret, "sensorName");
300 if (strcpy_s(config->sensorInfo.sensorName, SENSOR_INFO_NAME_MAX_LEN, name) != EOK) {
301 HDF_LOGE("%s:copy sensorName failed!", __func__);
302 return HDF_FAILURE;
303 }
304
305 ret = parser->GetString(infoNode, "vendorName", &name, NULL);
306 CHECK_PARSER_RESULT_RETURN_VALUE(ret, "vendorName");
307 if (strcpy_s(config->sensorInfo.vendorName, SENSOR_INFO_NAME_MAX_LEN, name) != EOK) {
308 HDF_LOGE("%s:copy vendorName failed!", __func__);
309 return HDF_FAILURE;
310 }
311
312 ret = parser->GetString(infoNode, "firmwareVersion", &name, NULL);
313 CHECK_PARSER_RESULT_RETURN_VALUE(ret, "firmwareVersion");
314 if (strcpy_s(config->sensorInfo.firmwareVersion, SENSOR_INFO_VERSION_MAX_LEN, name) != EOK) {
315 HDF_LOGE("%s:copy firmwareVersion failed!", __func__);
316 return HDF_FAILURE;
317 }
318
319 ret = parser->GetString(infoNode, "hardwareVersion", &name, NULL);
320 CHECK_PARSER_RESULT_RETURN_VALUE(ret, "hardwareVersion");
321 if (strcpy_s(config->sensorInfo.hardwareVersion, SENSOR_INFO_VERSION_MAX_LEN, name) != EOK) {
322 HDF_LOGE("%s:copy hardwareVersion failed!", __func__);
323 return HDF_FAILURE;
324 }
325
326 ret = parser->GetUint16(infoNode, "sensorTypeId", &id, 0);
327 CHECK_PARSER_RESULT_RETURN_VALUE(ret, "sensorTypeId");
328 config->sensorInfo.sensorTypeId = id;
329 ret = parser->GetUint16(infoNode, "sensorId", &id, 0);
330 CHECK_PARSER_RESULT_RETURN_VALUE(ret, "sensorId");
331 config->sensorInfo.sensorId = id;
332
333 ret = parser->GetUint32(infoNode, "maxRange", (uint32_t *)&value, 0);
334 CHECK_PARSER_RESULT_RETURN_VALUE(ret, "maxRange");
335 config->sensorInfo.maxRange = value;
336 ret = parser->GetUint32(infoNode, "accuracy", (uint32_t *)&value, 0);
337 CHECK_PARSER_RESULT_RETURN_VALUE(ret, "accuracy");
338 config->sensorInfo.accuracy = value;
339 ret = parser->GetUint32(infoNode, "power", (uint32_t *)&value, 0);
340 CHECK_PARSER_RESULT_RETURN_VALUE(ret, "power");
341 config->sensorInfo.power = value;
342
343 return ret;
344 }
345
ParseSensorBus(struct DeviceResourceIface * parser,const struct DeviceResourceNode * busNode,struct SensorCfgData * config)346 static int32_t ParseSensorBus(struct DeviceResourceIface *parser, const struct DeviceResourceNode *busNode,
347 struct SensorCfgData *config)
348 {
349 int32_t ret;
350
351 ret = parser->GetUint8(busNode, "busType", &config->busCfg.busType, 0);
352 CHECK_PARSER_RESULT_RETURN_VALUE(ret, "busType");
353 ret = parser->GetUint8(busNode, "regBigEndian", &config->busCfg.regBigEndian, 0);
354 CHECK_PARSER_RESULT_RETURN_VALUE(ret, "regBigEndian");
355
356 if (config->busCfg.busType == SENSOR_BUS_I2C) {
357 ret = parser->GetUint16(busNode, "busNum", &config->busCfg.i2cCfg.busNum, 0);
358 CHECK_PARSER_RESULT_RETURN_VALUE(ret, "busNum");
359 ret = parser->GetUint16(busNode, "busAddr", &config->busCfg.i2cCfg.devAddr, 0);
360 CHECK_PARSER_RESULT_RETURN_VALUE(ret, "busAddr");
361 ret = parser->GetUint16(busNode, "regWidth", &config->busCfg.i2cCfg.regWidth, 0);
362 CHECK_PARSER_RESULT_RETURN_VALUE(ret, "regWidth");
363 } else if (config->busCfg.busType == SENSOR_BUS_SPI) {
364 ret = parser->GetUint32(busNode, "busNum", &config->busCfg.spiCfg.busNum, 0);
365 CHECK_PARSER_RESULT_RETURN_VALUE(ret, "busNum");
366 ret = parser->GetUint32(busNode, "busAddr", &config->busCfg.spiCfg.csNum, 0);
367 CHECK_PARSER_RESULT_RETURN_VALUE(ret, "busAddr");
368 } else if (config->busCfg.busType == SENSOR_BUS_GPIO) {
369 ret = parser->GetUint32(busNode, "gpioIrq1", &config->busCfg.GpioNum[SENSOR_GPIO_NUM1], 0);
370 CHECK_PARSER_RESULT_RETURN_VALUE(ret, "gpioIrq1");
371 ret = parser->GetUint32(busNode, "gpioIrq2", &config->busCfg.GpioNum[SENSOR_GPIO_NUM2], 0);
372 CHECK_PARSER_RESULT_RETURN_VALUE(ret, "gpioIrq2");
373 }
374
375 return HDF_SUCCESS;
376 }
377
ParseSensorAttr(struct DeviceResourceIface * parser,const struct DeviceResourceNode * attrNode,struct SensorCfgData * config)378 static int32_t ParseSensorAttr(struct DeviceResourceIface *parser, const struct DeviceResourceNode *attrNode,
379 struct SensorCfgData *config)
380 {
381 int32_t ret;
382 ret = parser->GetString(attrNode, "chipName", &config->sensorAttr.chipName, NULL);
383 CHECK_PARSER_RESULT_RETURN_VALUE(ret, "chipName");
384 ret = parser->GetUint16(attrNode, "chipIdRegister", &config->sensorAttr.chipIdReg, 0);
385 CHECK_PARSER_RESULT_RETURN_VALUE(ret, "chipIdRegister");
386 ret = parser->GetUint16(attrNode, "chipIdValue", &config->sensorAttr.chipIdValue, 0);
387 CHECK_PARSER_RESULT_RETURN_VALUE(ret, "chipIdValue");
388
389 return ret;
390 }
391
ReleaseSensorDirectionConfig(struct SensorCfgData * config)392 void ReleaseSensorDirectionConfig(struct SensorCfgData *config)
393 {
394 CHECK_NULL_PTR_RETURN(config);
395
396 if (config->direction != NULL) {
397 OsalMemFree(config->direction);
398 config->direction = NULL;
399 }
400 }
401
ParseSensorDirection(struct SensorCfgData * config)402 int32_t ParseSensorDirection(struct SensorCfgData *config)
403 {
404 int32_t num;
405 int32_t ret;
406 uint32_t index;
407 uint32_t *buf = NULL;
408 const struct DeviceResourceNode *directionNode = NULL;
409 struct DeviceResourceIface *parser = NULL;
410
411 CHECK_NULL_PTR_RETURN_VALUE(config->root, HDF_ERR_INVALID_PARAM);
412 parser = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
413 CHECK_NULL_PTR_RETURN_VALUE(parser, HDF_ERR_INVALID_PARAM);
414
415 directionNode = parser->GetChildNode(config->root, "sensorDirection");
416 CHECK_NULL_PTR_RETURN_VALUE(directionNode, HDF_ERR_INVALID_PARAM);
417
418 num = parser->GetElemNum(directionNode, "convert");
419 ret = parser->GetUint32(directionNode, "direction", &index, 0);
420 CHECK_PARSER_RESULT_RETURN_VALUE(ret, "direction");
421 if ((num <= 0 || num > MAX_SENSOR_INDEX_NUM) || (index < 0 || (int32_t)index > num / AXIS_INDEX_MAX)) {
422 return HDF_FAILURE;
423 }
424
425 buf = (uint32_t *)OsalMemCalloc(sizeof(uint32_t) * num);
426 CHECK_NULL_PTR_RETURN_VALUE(buf, HDF_ERR_MALLOC_FAIL);
427
428 ret = parser->GetUint32Array(directionNode, "convert", buf, num, 0);
429 if (ret != HDF_SUCCESS) {
430 HDF_LOGE("%s: parser %s convert failed", __func__, "convert");
431 OsalMemFree(buf);
432 return HDF_FAILURE;
433 }
434
435 config->direction = (struct SensorDirection*)OsalMemCalloc(sizeof(struct SensorDirection));
436 if (config->direction == NULL) {
437 HDF_LOGE("%s: malloc sensor direction config item failed", __func__);
438 OsalMemFree(buf);
439 return HDF_ERR_MALLOC_FAIL;
440 }
441
442 index = index * AXIS_INDEX_MAX;
443 config->direction->sign[AXIS_X] = buf[index + SIGN_X_INDEX];
444 config->direction->sign[AXIS_Y] = buf[index + SIGN_Y_INDEX];
445 config->direction->sign[AXIS_Z] = buf[index + SIGN_Z_INDEX];
446 config->direction->map[AXIS_X] = buf[index + AXIS_X_INDEX];
447 config->direction->map[AXIS_Y] = buf[index + AXIS_Y_INDEX];
448 config->direction->map[AXIS_Z] = buf[index + AXIS_Z_INDEX];
449
450 OsalMemFree(buf);
451 return HDF_SUCCESS;
452 }
453
SensorRawDataToRemapData(struct SensorDirection * direction,int32_t * remapData,uint32_t num)454 int32_t SensorRawDataToRemapData(struct SensorDirection *direction, int32_t *remapData, uint32_t num)
455 {
456 uint32_t axis;
457 int32_t directionSign[MAX_SENSOR_AXIS_NUM];
458 int32_t newData[MAX_SENSOR_AXIS_NUM];
459
460 CHECK_NULL_PTR_RETURN_VALUE(direction, HDF_ERR_INVALID_PARAM);
461
462 for (axis = 0; axis < num; axis++) {
463 if (direction->sign[axis] == 0) {
464 directionSign[axis] = 1;
465 } else {
466 directionSign[axis] = -1;
467 }
468 }
469
470 newData[direction->map[AXIS_X]] = directionSign[AXIS_X] * remapData[AXIS_X];
471 newData[direction->map[AXIS_Y]] = directionSign[AXIS_Y] * remapData[AXIS_Y];
472 newData[direction->map[AXIS_Z]] = directionSign[AXIS_Z] * remapData[AXIS_Z];
473
474 remapData[AXIS_X] = newData[direction->map[AXIS_X]];
475 remapData[AXIS_Y] = newData[direction->map[AXIS_Y]];
476 remapData[AXIS_Z] = newData[direction->map[AXIS_Z]];
477
478 return HDF_SUCCESS;
479 }
480
GetSensorBaseConfigData(const struct DeviceResourceNode * node,struct SensorCfgData * config)481 int32_t GetSensorBaseConfigData(const struct DeviceResourceNode *node, struct SensorCfgData *config)
482 {
483 int32_t ret;
484 struct DeviceResourceIface *parser = NULL;
485 const struct DeviceResourceNode *infoNode = NULL;
486 const struct DeviceResourceNode *busNode = NULL;
487 const struct DeviceResourceNode *attrNode = NULL;
488
489 CHECK_NULL_PTR_RETURN_VALUE(node, HDF_ERR_INVALID_PARAM);
490 CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM);
491
492 parser = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
493 CHECK_NULL_PTR_RETURN_VALUE(parser, HDF_ERR_INVALID_PARAM);
494
495 config->root = node;
496 CHECK_NULL_PTR_RETURN_VALUE(parser->GetChildNode, HDF_ERR_INVALID_PARAM);
497
498 infoNode = parser->GetChildNode(node, "sensorInfo");
499 if (infoNode != NULL) {
500 ret = ParseSensorInfo(parser, infoNode, config);
501 CHECK_PARSER_RESULT_RETURN_VALUE(ret, "sensorInfo");
502 }
503
504 busNode = parser->GetChildNode(node, "sensorBusConfig");
505 if (busNode != NULL) {
506 ret = ParseSensorBus(parser, busNode, config);
507 CHECK_PARSER_RESULT_RETURN_VALUE(ret, "sensorBusConfig");
508 }
509
510 attrNode = parser->GetChildNode(node, "sensorIdAttr");
511 if (attrNode != NULL) {
512 ret = ParseSensorAttr(parser, attrNode, config);
513 CHECK_PARSER_RESULT_RETURN_VALUE(ret, "sensorIdAttr");
514 }
515
516 return HDF_SUCCESS;
517 }
518