1 /*
2 * Copyright (c) 2023 Wuerth Elektronik eiSos GmbH & Co. KG
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 /**
8 * @file
9 * @brief Driver file for the WSEN-ITDS sensor.
10 */
11
12 #include "WSEN_ITDS_2533020201601.h"
13
14 #include <stdio.h>
15
16 #include <weplatform.h>
17
18 /**
19 * @brief Default sensor interface configuration.
20 */
21 static WE_sensorInterface_t itdsDefaultSensorInterface = {
22 .sensorType = WE_ITDS,
23 .interfaceType = WE_i2c,
24 .options = {.i2c = {.address = ITDS_ADDRESS_I2C_1, .burstMode = 0, .slaveTransmitterMode = 0, .useRegAddrMsbForMultiBytesRead = 0, .reserved = 0},
25 .spi = {.chipSelectPort = 0, .chipSelectPin = 0, .burstMode = 0, .reserved = 0},
26 .readTimeout = 1000,
27 .writeTimeout = 1000},
28 .handle = 0};
29
30
31 /**
32 * @brief Stores the current value of the full scale parameter.
33 * default for full scale (e.g. after soft reset of sensor): '00' = 2G
34 *
35 * The value is updated when calling ITDS_setFullScale() or
36 * ITDS_getFullScale().
37 *
38 */
39 static ITDS_fullScale_t currentFullScale = ITDS_twoG;
40
41
42 /**
43 * @brief Read data from sensor.
44 *
45 * @param[in] sensorInterface Pointer to sensor interface
46 * @param[in] regAdr Address of register to read from
47 * @param[in] numBytesToRead Number of bytes to be read
48 * @param[out] data Target buffer
49 * @return Error Code
50 */
ITDS_ReadReg(WE_sensorInterface_t * sensorInterface,uint8_t regAdr,uint16_t numBytesToRead,uint8_t * data)51 static inline int8_t ITDS_ReadReg(WE_sensorInterface_t* sensorInterface,
52 uint8_t regAdr,
53 uint16_t numBytesToRead,
54 uint8_t *data)
55 {
56 return WE_ReadReg(sensorInterface, regAdr, numBytesToRead, data);
57 }
58
59 /**
60 * @brief Write data to sensor.
61 *
62 * @param[in] sensorInterface Pointer to sensor interface
63 * @param[in] regAdr Address of register to write to
64 * @param[in] numBytesToWrite Number of bytes to be written
65 * @param[in] data Source buffer
66 * @return Error Code
67 */
ITDS_WriteReg(WE_sensorInterface_t * sensorInterface,uint8_t regAdr,uint16_t numBytesToWrite,uint8_t * data)68 static inline int8_t ITDS_WriteReg(WE_sensorInterface_t* sensorInterface,
69 uint8_t regAdr,
70 uint16_t numBytesToWrite,
71 uint8_t *data)
72 {
73 return WE_WriteReg(sensorInterface, regAdr, numBytesToWrite, data);
74 }
75
76 /**
77 * @brief Returns the default sensor interface configuration.
78 * @param[out] sensorInterface Sensor interface configuration (output parameter)
79 * @return Error code
80 */
ITDS_getDefaultInterface(WE_sensorInterface_t * sensorInterface)81 int8_t ITDS_getDefaultInterface(WE_sensorInterface_t* sensorInterface)
82 {
83 *sensorInterface = itdsDefaultSensorInterface;
84 return WE_SUCCESS;
85 }
86
87 /**
88 * @brief Read the device ID
89 *
90 * Expected value is ITDS_DEVICE_ID_VALUE.
91 *
92 * @param[in] sensorInterface Pointer to sensor interface
93 * @param[out] deviceID The returned device ID.
94 * @retval Error code
95 */
ITDS_getDeviceID(WE_sensorInterface_t * sensorInterface,uint8_t * deviceID)96 int8_t ITDS_getDeviceID(WE_sensorInterface_t* sensorInterface, uint8_t *deviceID)
97 {
98 return ITDS_ReadReg(sensorInterface, ITDS_DEVICE_ID_REG, 1, deviceID);
99 }
100
101
102 /* CTRL_1 */
103
104 /**
105 * @brief Set the output data rate
106 * @param[in] sensorInterface Pointer to sensor interface
107 * @param[in] odr Output data rate
108 * @retval Error code
109 */
ITDS_setOutputDataRate(WE_sensorInterface_t * sensorInterface,ITDS_outputDataRate_t odr)110 int8_t ITDS_setOutputDataRate(WE_sensorInterface_t* sensorInterface, ITDS_outputDataRate_t odr)
111 {
112 ITDS_ctrl1_t ctrl1;
113
114 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_1_REG, 1, (uint8_t *) &ctrl1))
115 {
116 return WE_FAIL;
117 }
118
119 ctrl1.outputDataRate = odr;
120
121 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_1_REG, 1, (uint8_t *) &ctrl1);
122 }
123
124 /**
125 * @brief Read the output data rate
126 * @param[in] sensorInterface Pointer to sensor interface
127 * @param[out] odr The returned output data rate.
128 * @retval Error code
129 */
ITDS_getOutputDataRate(WE_sensorInterface_t * sensorInterface,ITDS_outputDataRate_t * odr)130 int8_t ITDS_getOutputDataRate(WE_sensorInterface_t* sensorInterface, ITDS_outputDataRate_t *odr)
131 {
132 ITDS_ctrl1_t ctrl1;
133
134 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_1_REG, 1, (uint8_t *) &ctrl1))
135 {
136 return WE_FAIL;
137 }
138
139 *odr = (ITDS_outputDataRate_t) ctrl1.outputDataRate;
140
141 return WE_SUCCESS;
142 }
143
144 /**
145 * @brief Set the operating mode
146 * @param[in] sensorInterface Pointer to sensor interface
147 * @param[in] opMode Operating mode
148 * @retval Error code
149 */
ITDS_setOperatingMode(WE_sensorInterface_t * sensorInterface,ITDS_operatingMode_t opMode)150 int8_t ITDS_setOperatingMode(WE_sensorInterface_t* sensorInterface, ITDS_operatingMode_t opMode)
151 {
152 ITDS_ctrl1_t ctrl1;
153
154 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_1_REG, 1, (uint8_t *) &ctrl1))
155 {
156 return WE_FAIL;
157 }
158
159 ctrl1.operatingMode = opMode;
160
161 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_1_REG, 1, (uint8_t *) &ctrl1);
162 }
163
164 /**
165 * @brief Read the operating mode
166 * @param[in] sensorInterface Pointer to sensor interface
167 * @param[out] opMode The returned operating mode.
168 * @retval Error code
169 */
ITDS_getOperatingMode(WE_sensorInterface_t * sensorInterface,ITDS_operatingMode_t * opMode)170 int8_t ITDS_getOperatingMode(WE_sensorInterface_t* sensorInterface, ITDS_operatingMode_t *opMode)
171 {
172 ITDS_ctrl1_t ctrl1;
173
174 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_1_REG, 1, (uint8_t *) &ctrl1))
175 {
176 return WE_FAIL;
177 }
178
179 *opMode = (ITDS_operatingMode_t) ctrl1.operatingMode;
180
181 return WE_SUCCESS;
182 }
183
184 /**
185 * @brief Set the power mode
186 * @param[in] sensorInterface Pointer to sensor interface
187 * @param[in] powerMode Power mode
188 * @retval Error code
189 */
ITDS_setPowerMode(WE_sensorInterface_t * sensorInterface,ITDS_powerMode_t powerMode)190 int8_t ITDS_setPowerMode(WE_sensorInterface_t* sensorInterface, ITDS_powerMode_t powerMode)
191 {
192 ITDS_ctrl1_t ctrl1;
193
194 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_1_REG, 1, (uint8_t *) &ctrl1))
195 {
196 return WE_FAIL;
197 }
198
199 ctrl1.powerMode = powerMode;
200
201 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_1_REG, 1, (uint8_t *) &ctrl1);
202 }
203
204 /**
205 * @brief Read the power mode
206 * @param[in] sensorInterface Pointer to sensor interface
207 * @param[out] powerMode The returned power mode.
208 * @retval Error code
209 */
ITDS_getPowerMode(WE_sensorInterface_t * sensorInterface,ITDS_powerMode_t * powerMode)210 int8_t ITDS_getPowerMode(WE_sensorInterface_t* sensorInterface, ITDS_powerMode_t *powerMode)
211 {
212 ITDS_ctrl1_t ctrl1;
213
214 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_1_REG, 1, (uint8_t *) &ctrl1))
215 {
216 return WE_FAIL;
217 }
218
219 *powerMode = ctrl1.powerMode;
220
221 return WE_SUCCESS;
222 }
223
224 /* CTRL REG 2 */
225
226 /**
227 * @brief (Re)boot the device [enabled, disabled]
228 * @param[in] sensorInterface Pointer to sensor interface
229 * @param[in] reboot Reboot state
230 * @retval Error code
231 */
ITDS_reboot(WE_sensorInterface_t * sensorInterface,ITDS_state_t reboot)232 int8_t ITDS_reboot(WE_sensorInterface_t* sensorInterface, ITDS_state_t reboot)
233 {
234 ITDS_ctrl2_t ctrl2;
235
236 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_2_REG, 1, (uint8_t *) &ctrl2))
237 {
238 return WE_FAIL;
239 }
240
241 ctrl2.boot = reboot;
242
243 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_2_REG, 1, (uint8_t *) &ctrl2);
244 }
245
246 /**
247 * @brief Read the reboot state
248 * @param[in] sensorInterface Pointer to sensor interface
249 * @param[out] rebooting The returned reboot state.
250 * @retval Error code
251 */
ITDS_isRebooting(WE_sensorInterface_t * sensorInterface,ITDS_state_t * rebooting)252 int8_t ITDS_isRebooting(WE_sensorInterface_t* sensorInterface, ITDS_state_t *rebooting)
253 {
254 ITDS_ctrl2_t ctrl2;
255
256 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_2_REG, 1, (uint8_t *) &ctrl2))
257 {
258 return WE_FAIL;
259 }
260
261 *rebooting = (ITDS_state_t) ctrl2.boot;
262
263 return WE_SUCCESS;
264 }
265
266 /**
267 * @brief Set software reset [enabled, disabled]
268 * @param[in] sensorInterface Pointer to sensor interface
269 * @param[in] swReset Software reset state
270 * @retval Error code
271 */
ITDS_softReset(WE_sensorInterface_t * sensorInterface,ITDS_state_t swReset)272 int8_t ITDS_softReset(WE_sensorInterface_t* sensorInterface, ITDS_state_t swReset)
273 {
274 ITDS_ctrl2_t ctrl2;
275
276 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_2_REG, 1, (uint8_t *) &ctrl2))
277 {
278 return WE_FAIL;
279 }
280
281 ctrl2.softReset = swReset;
282
283 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_2_REG, 1, (uint8_t *) &ctrl2);
284 }
285
286 /**
287 * @brief Read the software reset state [enabled, disabled]
288 * @param[in] sensorInterface Pointer to sensor interface
289 * @param[out] swReset The returned software reset state.
290 * @retval Error code
291 */
ITDS_getSoftResetState(WE_sensorInterface_t * sensorInterface,ITDS_state_t * swReset)292 int8_t ITDS_getSoftResetState(WE_sensorInterface_t* sensorInterface, ITDS_state_t *swReset)
293 {
294 ITDS_ctrl2_t ctrl2;
295
296 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_2_REG, 1, (uint8_t *) &ctrl2))
297 {
298 return WE_FAIL;
299 }
300
301 *swReset = (ITDS_state_t) ctrl2.softReset;
302
303 return WE_SUCCESS;
304 }
305
306 /**
307 * @brief Disconnect CS pin pull up [pull up connected, pull up disconnected]
308 * @param[in] sensorInterface Pointer to sensor interface
309 * @param[in] disconnectPU CS pin pull up state
310 * @retval Error code
311 */
ITDS_setCSPullUpDisconnected(WE_sensorInterface_t * sensorInterface,ITDS_state_t disconnectPU)312 int8_t ITDS_setCSPullUpDisconnected(WE_sensorInterface_t* sensorInterface, ITDS_state_t disconnectPU)
313 {
314 ITDS_ctrl2_t ctrl2;
315
316 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_2_REG, 1, (uint8_t *) &ctrl2))
317 {
318 return WE_FAIL;
319 }
320
321 ctrl2.disCSPullUp = disconnectPU;
322
323 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_2_REG, 1, (uint8_t *) &ctrl2);
324 }
325
326 /**
327 * @brief Read the CS pin pull up state [pull up connected, pull up disconnected]
328 * @param[in] sensorInterface Pointer to sensor interface
329 * @param[out] puDisconnected The returned CS pin pull up state
330 * @retval Error code
331 */
ITDS_isCSPullUpDisconnected(WE_sensorInterface_t * sensorInterface,ITDS_state_t * puDisconnected)332 int8_t ITDS_isCSPullUpDisconnected(WE_sensorInterface_t* sensorInterface, ITDS_state_t *puDisconnected)
333 {
334 ITDS_ctrl2_t ctrl2;
335
336 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_2_REG, 1, (uint8_t *) &ctrl2))
337 {
338 return WE_FAIL;
339 }
340
341 *puDisconnected = (ITDS_state_t) ctrl2.disCSPullUp;
342
343 return WE_SUCCESS;
344 }
345
346
347 /**
348 * @brief Enable/disable block data update mode
349 * @param[in] sensorInterface Pointer to sensor interface
350 * @param[in] bdu Block data update state
351 * @retval Error code
352 */
ITDS_enableBlockDataUpdate(WE_sensorInterface_t * sensorInterface,ITDS_state_t bdu)353 int8_t ITDS_enableBlockDataUpdate(WE_sensorInterface_t* sensorInterface, ITDS_state_t bdu)
354 {
355 ITDS_ctrl2_t ctrl2;
356
357 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_2_REG, 1, (uint8_t *) &ctrl2))
358 {
359 return WE_FAIL;
360 }
361
362 ctrl2.blockDataUpdate = bdu;
363
364 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_2_REG, 1, (uint8_t *) &ctrl2);
365 }
366
367 /**
368 * @brief Read the block data update state
369 * @param[in] sensorInterface Pointer to sensor interface
370 * @param[out] bdu The returned block data update state
371 * @retval Error code
372 */
ITDS_isBlockDataUpdateEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * bdu)373 int8_t ITDS_isBlockDataUpdateEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *bdu)
374 {
375 ITDS_ctrl2_t ctrl2;
376
377 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_2_REG, 1, (uint8_t *) &ctrl2))
378 {
379 return WE_FAIL;
380 }
381 *bdu = (ITDS_state_t) ctrl2.blockDataUpdate;
382
383 return WE_SUCCESS;
384 }
385
386 /**
387 * @brief Enable/disable auto increment mode
388 * @param[in] sensorInterface Pointer to sensor interface
389 * @param[in] autoIncr Auto increment mode state
390 * @retval Error code
391 */
ITDS_enableAutoIncrement(WE_sensorInterface_t * sensorInterface,ITDS_state_t autoIncr)392 int8_t ITDS_enableAutoIncrement(WE_sensorInterface_t* sensorInterface, ITDS_state_t autoIncr)
393 {
394 ITDS_ctrl2_t ctrl2;
395
396 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_2_REG, 1, (uint8_t *) &ctrl2))
397 {
398 return WE_FAIL;
399 }
400
401 ctrl2.autoAddIncr = autoIncr;
402
403 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_2_REG, 1, (uint8_t *) &ctrl2);
404 }
405
406 /**
407 * @brief Read the auto increment mode state
408 * @param[in] sensorInterface Pointer to sensor interface
409 * @param[out] autoIncr The returned auto increment mode state
410 * @retval Error code
411 */
ITDS_isAutoIncrementEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * autoIncr)412 int8_t ITDS_isAutoIncrementEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *autoIncr)
413 {
414 ITDS_ctrl2_t ctrl2;
415
416 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_2_REG, 1, (uint8_t *) &ctrl2))
417 {
418 return WE_FAIL;
419 }
420
421 *autoIncr = (ITDS_state_t) ctrl2.autoAddIncr;
422
423 return WE_SUCCESS;
424 }
425
426 /**
427 * @brief Disable the I2C interface
428 * @param[in] sensorInterface Pointer to sensor interface
429 * @param[in] i2cDisable I2C interface disable state (0: I2C enabled, 1: I2C disabled)
430 * @retval Error code
431 */
ITDS_disableI2CInterface(WE_sensorInterface_t * sensorInterface,ITDS_state_t i2cDisable)432 int8_t ITDS_disableI2CInterface(WE_sensorInterface_t* sensorInterface, ITDS_state_t i2cDisable)
433 {
434 ITDS_ctrl2_t ctrl2;
435
436 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_2_REG, 1, (uint8_t *) &ctrl2))
437 {
438 return WE_FAIL;
439 }
440
441 ctrl2.i2cDisable = i2cDisable;
442
443 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_2_REG, 1, (uint8_t *) &ctrl2);
444 }
445
446 /**
447 * @brief Read the I2C interface disable state [enabled, disabled]
448 * @param[in] sensorInterface Pointer to sensor interface
449 * @param[out] i2cDisabled The returned I2C interface disable state (0: I2C enabled, 1: I2C disabled)
450 * @retval Error code
451 */
ITDS_isI2CInterfaceDisabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * i2cDisabled)452 int8_t ITDS_isI2CInterfaceDisabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *i2cDisabled)
453 {
454 ITDS_ctrl2_t ctrl2;
455
456 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_2_REG, 1, (uint8_t *) &ctrl2))
457 {
458 return WE_FAIL;
459 }
460
461 *i2cDisabled = (ITDS_state_t) ctrl2.i2cDisable;
462
463 return WE_SUCCESS;
464 }
465
466
467 /* CTRL REG 3 */
468
469 /**
470 * @brief Set self test mode
471 * @param[in] sensorInterface Pointer to sensor interface
472 * @param[in] selfTest Self test mode
473 * @retval Error code
474 */
ITDS_setSelfTestMode(WE_sensorInterface_t * sensorInterface,ITDS_selfTestConfig_t selfTest)475 int8_t ITDS_setSelfTestMode(WE_sensorInterface_t* sensorInterface, ITDS_selfTestConfig_t selfTest)
476 {
477 ITDS_ctrl3_t ctrl3;
478
479 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_3_REG, 1, (uint8_t *) &ctrl3))
480 {
481 return WE_FAIL;
482 }
483
484 ctrl3.selfTestMode = selfTest;
485
486 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_3_REG, 1, (uint8_t *) &ctrl3);
487 }
488
489 /**
490 * @brief Read the self test mode
491 * @param[in] sensorInterface Pointer to sensor interface
492 * @param[out] selfTest The returned self test mode
493 * @retval Error code
494 */
ITDS_getSelfTestMode(WE_sensorInterface_t * sensorInterface,ITDS_selfTestConfig_t * selfTest)495 int8_t ITDS_getSelfTestMode(WE_sensorInterface_t* sensorInterface, ITDS_selfTestConfig_t *selfTest)
496 {
497 ITDS_ctrl3_t ctrl3;
498
499 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_3_REG, 1, (uint8_t *) &ctrl3))
500 {
501 return WE_FAIL;
502 }
503
504 *selfTest = (ITDS_selfTestConfig_t) ctrl3.selfTestMode;
505
506 return WE_SUCCESS;
507 }
508
509 /**
510 * @brief Set the interrupt pin type [push-pull/open-drain]
511 * @param[in] sensorInterface Pointer to sensor interface
512 * @param[in] pinType Interrupt pin type
513 * @retval Error code
514 */
ITDS_setInterruptPinType(WE_sensorInterface_t * sensorInterface,ITDS_interruptPinConfig_t pinType)515 int8_t ITDS_setInterruptPinType(WE_sensorInterface_t* sensorInterface, ITDS_interruptPinConfig_t pinType)
516 {
517 ITDS_ctrl3_t ctrl3;
518
519 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_3_REG, 1, (uint8_t *) &ctrl3))
520 {
521 return WE_FAIL;
522 }
523
524 ctrl3.intPinConf = pinType;
525
526 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_3_REG, 1, (uint8_t *) &ctrl3);
527 }
528
529 /**
530 * @brief Read the interrupt pin type [push-pull/open-drain]
531 * @param[in] sensorInterface Pointer to sensor interface
532 * @param[out] pinType The returned interrupt pin type.
533 * @retval Error code
534 */
ITDS_getInterruptPinType(WE_sensorInterface_t * sensorInterface,ITDS_interruptPinConfig_t * pinType)535 int8_t ITDS_getInterruptPinType(WE_sensorInterface_t* sensorInterface, ITDS_interruptPinConfig_t *pinType)
536 {
537 ITDS_ctrl3_t ctrl3;
538
539 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_3_REG, 1, (uint8_t *) &ctrl3))
540 {
541 return WE_FAIL;
542 }
543
544 *pinType = (ITDS_interruptPinConfig_t) ctrl3.intPinConf;
545
546 return WE_SUCCESS;
547 }
548
549 /**
550 * @brief Enable/disable latched interrupts
551 * @param[in] sensorInterface Pointer to sensor interface
552 * @param[in] lir Latched interrupts state
553 * @retval Error code
554 */
ITDS_enableLatchedInterrupt(WE_sensorInterface_t * sensorInterface,ITDS_state_t lir)555 int8_t ITDS_enableLatchedInterrupt(WE_sensorInterface_t* sensorInterface, ITDS_state_t lir)
556 {
557 ITDS_ctrl3_t ctrl3;
558
559 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_3_REG, 1, (uint8_t *) &ctrl3))
560 {
561 return WE_FAIL;
562 }
563
564 ctrl3.enLatchedInterrupt = lir;
565
566 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_3_REG, 1, (uint8_t *) &ctrl3);
567 }
568
569 /**
570 * @brief Read the latched interrupts state [enabled, disabled]
571 * @param[in] sensorInterface Pointer to sensor interface
572 * @param[out] lir The returned latched interrupts state.
573 * @retval Error code
574 */
ITDS_isLatchedInterruptEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * lir)575 int8_t ITDS_isLatchedInterruptEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *lir)
576 {
577 ITDS_ctrl3_t ctrl3;
578
579 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_3_REG, 1, (uint8_t *) &ctrl3))
580 {
581 return WE_FAIL;
582 }
583
584 *lir = (ITDS_state_t) ctrl3.enLatchedInterrupt;
585
586 return WE_SUCCESS;
587 }
588
589 /**
590 * @brief Set the interrupt active level [active high/active low]
591 * @param[in] sensorInterface Pointer to sensor interface
592 * @param[in] level Interrupt active level
593 * @retval Error code
594 */
ITDS_setInterruptActiveLevel(WE_sensorInterface_t * sensorInterface,ITDS_interruptActiveLevel_t level)595 int8_t ITDS_setInterruptActiveLevel(WE_sensorInterface_t* sensorInterface, ITDS_interruptActiveLevel_t level)
596 {
597 ITDS_ctrl3_t ctrl3;
598
599 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_3_REG, 1, (uint8_t *) &ctrl3))
600 {
601 return WE_FAIL;
602 }
603
604 ctrl3.intActiveLevel = level;
605
606 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_3_REG, 1, (uint8_t *) &ctrl3);
607 }
608
609 /**
610 * @brief Read the interrupt active level
611 * @param[in] sensorInterface Pointer to sensor interface
612 * @param[out] level The returned interrupt active level
613 * @retval Error code
614 */
ITDS_getInterruptActiveLevel(WE_sensorInterface_t * sensorInterface,ITDS_interruptActiveLevel_t * level)615 int8_t ITDS_getInterruptActiveLevel(WE_sensorInterface_t* sensorInterface, ITDS_interruptActiveLevel_t *level)
616 {
617 ITDS_ctrl3_t ctrl3;
618
619 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_3_REG, 1, (uint8_t *) &ctrl3))
620 {
621 return WE_FAIL;
622 }
623
624 *level = (ITDS_interruptActiveLevel_t) ctrl3.intActiveLevel;
625
626 return WE_SUCCESS;
627 }
628
629 /**
630 * @brief Request single data conversion
631 * @param[in] sensorInterface Pointer to sensor interface
632 * @param[in] start Set to true to trigger single data conversion.
633 * @retval Error code
634 */
ITDS_startSingleDataConversion(WE_sensorInterface_t * sensorInterface,ITDS_state_t start)635 int8_t ITDS_startSingleDataConversion(WE_sensorInterface_t* sensorInterface, ITDS_state_t start)
636 {
637 ITDS_ctrl3_t ctrl3;
638
639 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_3_REG, 1, (uint8_t *) &ctrl3))
640 {
641 return WE_FAIL;
642 }
643
644 ctrl3.startSingleDataConv = start;
645
646 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_3_REG, 1, (uint8_t *) &ctrl3);
647 }
648
649 /**
650 * @brief Returns true if single data conversion has been requested.
651 * @param[in] sensorInterface Pointer to sensor interface
652 * @param[out] start Is set to true if single data conversion has been requested.
653 * @retval Error code
654 */
ITDS_isSingleDataConversionStarted(WE_sensorInterface_t * sensorInterface,ITDS_state_t * start)655 int8_t ITDS_isSingleDataConversionStarted(WE_sensorInterface_t* sensorInterface, ITDS_state_t *start)
656 {
657 ITDS_ctrl3_t ctrl3;
658
659 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_3_REG, 1, (uint8_t *) &ctrl3))
660 {
661 return WE_FAIL;
662 }
663
664 *start = (ITDS_state_t) ctrl3.startSingleDataConv;
665
666 return WE_SUCCESS;
667 }
668
669 /**
670 * @brief Set the single data conversion (on-demand) trigger.
671 * @param[in] sensorInterface Pointer to sensor interface
672 * @param[in] conversionTrigger Single data conversion (on-demand) trigger
673 * @retval Error code
674 */
ITDS_setSingleDataConversionTrigger(WE_sensorInterface_t * sensorInterface,ITDS_singleDataConversionTrigger_t conversionTrigger)675 int8_t ITDS_setSingleDataConversionTrigger(WE_sensorInterface_t* sensorInterface, ITDS_singleDataConversionTrigger_t conversionTrigger)
676 {
677 ITDS_ctrl3_t ctrl3;
678
679 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_3_REG, 1, (uint8_t *) &ctrl3))
680 {
681 return WE_FAIL;
682 }
683
684 ctrl3.singleConvTrigger = conversionTrigger;
685
686 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_3_REG, 1, (uint8_t *) &ctrl3);
687 }
688
689 /**
690 * @brief Read the single data conversion (on-demand) trigger
691 * @param[in] sensorInterface Pointer to sensor interface
692 * @param[out] conversionTrigger The returned single data conversion (on-demand) trigger.
693 * @retval Error code
694 */
ITDS_getSingleDataConversionTrigger(WE_sensorInterface_t * sensorInterface,ITDS_singleDataConversionTrigger_t * conversionTrigger)695 int8_t ITDS_getSingleDataConversionTrigger(WE_sensorInterface_t* sensorInterface, ITDS_singleDataConversionTrigger_t *conversionTrigger)
696 {
697 ITDS_ctrl3_t ctrl3;
698
699 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_3_REG, 1, (uint8_t *) &ctrl3))
700 {
701 return WE_FAIL;
702 }
703
704 *conversionTrigger = (ITDS_singleDataConversionTrigger_t) ctrl3.singleConvTrigger;
705
706 return WE_SUCCESS;
707 }
708
709
710 /* CTRL REG 4 */
711
712 /**
713 * @brief Enable/disable the 6D orientation changed interrupt on INT_0
714 * @param[in] sensorInterface Pointer to sensor interface
715 * @param[in] int06D The 6D orientation changed interrupt enable state
716 * @retval Error code
717 */
ITDS_enable6DOnINT0(WE_sensorInterface_t * sensorInterface,ITDS_state_t int06D)718 int8_t ITDS_enable6DOnINT0(WE_sensorInterface_t* sensorInterface, ITDS_state_t int06D)
719 {
720 ITDS_ctrl4_t ctrl4;
721
722 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_4_REG, 1, (uint8_t *) &ctrl4))
723 {
724 return WE_FAIL;
725 }
726
727 ctrl4.sixDINT0 = int06D;
728
729 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_4_REG, 1, (uint8_t *) &ctrl4);
730 }
731
732 /**
733 * @brief Check if the 6D interrupt on INT_0 is enabled
734 * @param[in] sensorInterface Pointer to sensor interface
735 * @param[out] int06D The returned 6D interrupt enable state
736 * @retval Error code
737 */
ITDS_is6DOnINT0Enabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * int06D)738 int8_t ITDS_is6DOnINT0Enabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *int06D)
739 {
740 ITDS_ctrl4_t ctrl4;
741
742 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_4_REG, 1, (uint8_t *) &ctrl4))
743 {
744 return WE_FAIL;
745 }
746
747 *int06D = (ITDS_state_t) ctrl4.sixDINT0;
748
749 return WE_SUCCESS;
750 }
751
752 /**
753 * @brief Enable/disable the single-tap interrupt on INT_0
754 * @param[in] sensorInterface Pointer to sensor interface
755 * @param[in] int0SingleTap Single-tap interrupt enable state
756 * @retval Error code
757 */
ITDS_enableSingleTapINT0(WE_sensorInterface_t * sensorInterface,ITDS_state_t int0SingleTap)758 int8_t ITDS_enableSingleTapINT0(WE_sensorInterface_t* sensorInterface, ITDS_state_t int0SingleTap)
759 {
760 ITDS_ctrl4_t ctrl4;
761
762 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_4_REG, 1, (uint8_t *) &ctrl4))
763 {
764 return WE_FAIL;
765 }
766
767 ctrl4.singleTapINT0 = int0SingleTap;
768
769 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_4_REG, 1, (uint8_t *) &ctrl4);
770 }
771
772 /**
773 * @brief Check if the single-tap interrupt on INT_0 is enabled
774 * @param[in] sensorInterface Pointer to sensor interface
775 * @param[out] int0SingleTap The returned single-tap interrupt enable state
776 * @retval Error code
777 */
ITDS_isSingleTapINT0Enabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * int0SingleTap)778 int8_t ITDS_isSingleTapINT0Enabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *int0SingleTap)
779 {
780 ITDS_ctrl4_t ctrl4;
781
782 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_4_REG, 1, (uint8_t *) &ctrl4))
783 {
784 return WE_FAIL;
785 }
786
787 *int0SingleTap = (ITDS_state_t) ctrl4.singleTapINT0;
788
789 return WE_SUCCESS;
790 }
791
792 /**
793 * @brief Enable/disable the wake-up interrupt on INT_0
794 * @param[in] sensorInterface Pointer to sensor interface
795 * @param[in] int0WakeUp Wake-up interrupt enable state
796 * @retval Error code
797 */
ITDS_enableWakeUpOnINT0(WE_sensorInterface_t * sensorInterface,ITDS_state_t int0WakeUp)798 int8_t ITDS_enableWakeUpOnINT0(WE_sensorInterface_t* sensorInterface, ITDS_state_t int0WakeUp)
799 {
800 ITDS_ctrl4_t ctrl4;
801
802 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_4_REG, 1, (uint8_t *) &ctrl4))
803 {
804 return WE_FAIL;
805 }
806
807 ctrl4.wakeUpINT0 = int0WakeUp;
808
809 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_4_REG, 1, (uint8_t *) &ctrl4);
810 }
811
812 /**
813 * @brief Check if the wake-up interrupt on INT_0 is enabled
814 * @param[in] sensorInterface Pointer to sensor interface
815 * @param[out] int0WakeUp The returned wake-up interrupt enable state
816 * @retval Error code
817 */
ITDS_isWakeUpOnINT0Enabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * int0WakeUp)818 int8_t ITDS_isWakeUpOnINT0Enabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *int0WakeUp)
819 {
820 ITDS_ctrl4_t ctrl4;
821
822 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_4_REG, 1, (uint8_t *) &ctrl4))
823 {
824 return WE_FAIL;
825 }
826
827 *int0WakeUp = (ITDS_state_t) ctrl4.wakeUpINT0;
828 return WE_SUCCESS;
829 }
830
831 /**
832 * @brief Enable/disable the free-fall interrupt on INT_0
833 * @param[in] sensorInterface Pointer to sensor interface
834 * @param[in] int0FreeFall Free-fall interrupt enable state
835 * @retval Error code
836 */
ITDS_enableFreeFallINT0(WE_sensorInterface_t * sensorInterface,ITDS_state_t int0FreeFall)837 int8_t ITDS_enableFreeFallINT0(WE_sensorInterface_t* sensorInterface, ITDS_state_t int0FreeFall)
838 {
839 ITDS_ctrl4_t ctrl4;
840
841 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_4_REG, 1, (uint8_t *) &ctrl4))
842 {
843 return WE_FAIL;
844 }
845
846 ctrl4.freeFallINT0 = int0FreeFall;
847
848 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_4_REG, 1, (uint8_t *) &ctrl4);
849 }
850
851 /**
852 * @brief Check if the free-fall interrupt on INT_0 is enabled
853 * @param[in] sensorInterface Pointer to sensor interface
854 * @param[out] int0FreeFall The returned free-fall enable state
855 * @retval Error code
856 */
ITDS_isFreeFallINT0Enabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * int0FreeFall)857 int8_t ITDS_isFreeFallINT0Enabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *int0FreeFall)
858 {
859 ITDS_ctrl4_t ctrl4;
860
861 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_4_REG, 1, (uint8_t *) &ctrl4))
862 {
863 return WE_FAIL;
864 }
865
866 *int0FreeFall = (ITDS_state_t) ctrl4.freeFallINT0;
867
868 return WE_SUCCESS;
869 }
870
871
872 /**
873 * @brief Enable/disable the double-tap interrupt on INT_0
874 * @param[in] sensorInterface Pointer to sensor interface
875 * @param[in] int0DoubleTap The double-tap interrupt enable state
876 * @retval Error code
877 */
ITDS_enableDoubleTapINT0(WE_sensorInterface_t * sensorInterface,ITDS_state_t int0DoubleTap)878 int8_t ITDS_enableDoubleTapINT0(WE_sensorInterface_t* sensorInterface, ITDS_state_t int0DoubleTap)
879 {
880 ITDS_ctrl4_t ctrl4;
881
882 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_4_REG, 1, (uint8_t *) &ctrl4))
883 {
884 return WE_FAIL;
885 }
886
887 ctrl4.doubleTapINT0 = int0DoubleTap;
888
889 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_4_REG, 1, (uint8_t *) &ctrl4);
890 }
891
892 /**
893 * @brief Check if the double-tap interrupt on INT_0 is enabled
894 * @param[in] sensorInterface Pointer to sensor interface
895 * @param[out] int0DoubleTap The returned double-tap interrupt enable state
896 * @retval Error code
897 */
ITDS_isDoubleTapINT0Enabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * int0DoubleTap)898 int8_t ITDS_isDoubleTapINT0Enabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *int0DoubleTap)
899 {
900 ITDS_ctrl4_t ctrl4;
901
902 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_4_REG, 1, (uint8_t *) &ctrl4))
903 {
904 return WE_FAIL;
905 }
906
907 *int0DoubleTap = (ITDS_state_t) ctrl4.doubleTapINT0;
908
909 return WE_SUCCESS;
910 }
911
912 /**
913 * @brief Enable/disable the FIFO full interrupt on INT_0
914 * @param[in] sensorInterface Pointer to sensor interface
915 * @param[in] int0FifoFull FIFO full interrupt enable state
916 * @retval Error code
917 */
ITDS_enableFifoFullINT0(WE_sensorInterface_t * sensorInterface,ITDS_state_t int0FifoFull)918 int8_t ITDS_enableFifoFullINT0(WE_sensorInterface_t* sensorInterface, ITDS_state_t int0FifoFull)
919 {
920 ITDS_ctrl4_t ctrl4;
921
922 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_4_REG, 1, (uint8_t *) &ctrl4))
923 {
924 return WE_FAIL;
925 }
926
927 ctrl4.fifoFullINT0 = int0FifoFull;
928
929 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_4_REG, 1, (uint8_t *) &ctrl4);
930 }
931
932 /**
933 * @brief Check if the FIFO full interrupt on INT_0 is enabled
934 * @param[in] sensorInterface Pointer to sensor interface
935 * @param[out] int0FifoFull The returned FIFO full interrupt enable state
936 * @retval Error code
937 */
ITDS_isFifoFullINT0Enabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * int0FifoFull)938 int8_t ITDS_isFifoFullINT0Enabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *int0FifoFull)
939 {
940 ITDS_ctrl4_t ctrl4;
941
942 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_4_REG, 1, (uint8_t *) &ctrl4))
943 {
944 return WE_FAIL;
945 }
946
947 *int0FifoFull = (ITDS_state_t) ctrl4.fifoFullINT0;
948
949 return WE_SUCCESS;
950 }
951
952 /**
953 * @brief Enable/disable the FIFO threshold interrupt on INT_0
954 * @param[in] sensorInterface Pointer to sensor interface
955 * @param[in] int0FifoThreshold FIFO threshold interrupt enable state
956 * @retval Error code
957 */
ITDS_enableFifoThresholdINT0(WE_sensorInterface_t * sensorInterface,ITDS_state_t int0FifoThreshold)958 int8_t ITDS_enableFifoThresholdINT0(WE_sensorInterface_t* sensorInterface, ITDS_state_t int0FifoThreshold)
959 {
960 ITDS_ctrl4_t ctrl4;
961
962 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_4_REG, 1, (uint8_t *) &ctrl4))
963 {
964 return WE_FAIL;
965 }
966
967 ctrl4.fifoThresholdINT0 = int0FifoThreshold;
968
969 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_4_REG, 1, (uint8_t *) &ctrl4);
970 }
971
972 /**
973 * @brief Check if the FIFO threshold interrupt on INT_0 is enabled
974 * @param[in] sensorInterface Pointer to sensor interface
975 * @param[out] int0FifoThreshold The returned FIFO threshold interrupt enable state
976 * @retval Error code
977 */
ITDS_isFifoThresholdINT0Enabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * int0FifoThreshold)978 int8_t ITDS_isFifoThresholdINT0Enabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *int0FifoThreshold)
979 {
980 ITDS_ctrl4_t ctrl4;
981
982 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_4_REG, 1, (uint8_t *) &ctrl4))
983 {
984 return WE_FAIL;
985 }
986
987 *int0FifoThreshold = (ITDS_state_t) ctrl4.fifoThresholdINT0;
988
989 return WE_SUCCESS;
990 }
991
992 /**
993 * @brief Enable/disable the data-ready interrupt on INT_0
994 * @param[in] sensorInterface Pointer to sensor interface
995 * @param[in] int0DataReady Data-ready interrupt enable state
996 * @retval Error code
997 */
ITDS_enableDataReadyINT0(WE_sensorInterface_t * sensorInterface,ITDS_state_t int0DataReady)998 int8_t ITDS_enableDataReadyINT0(WE_sensorInterface_t* sensorInterface, ITDS_state_t int0DataReady)
999 {
1000 ITDS_ctrl4_t ctrl4;
1001
1002 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_4_REG, 1, (uint8_t *) &ctrl4))
1003 {
1004 return WE_FAIL;
1005 }
1006
1007 ctrl4.dataReadyINT0 = int0DataReady;
1008
1009 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_4_REG, 1, (uint8_t *) &ctrl4);
1010 }
1011
1012 /**
1013 * @brief Check if the data-ready interrupt on INT_0 is enabled
1014 * @param[in] sensorInterface Pointer to sensor interface
1015 * @param[out] int0DataReady The returned data-ready interrupt enable State
1016 * @retval Error code
1017 */
ITDS_isDataReadyINT0Enabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * int0DataReady)1018 int8_t ITDS_isDataReadyINT0Enabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *int0DataReady)
1019 {
1020 ITDS_ctrl4_t ctrl4;
1021
1022 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_4_REG, 1, (uint8_t *) &ctrl4))
1023 {
1024 return WE_FAIL;
1025 }
1026
1027 *int0DataReady = (ITDS_state_t) ctrl4.dataReadyINT0;
1028
1029 return WE_SUCCESS;
1030 }
1031
1032
1033 /* CTRL REG 5 */
1034
1035 /**
1036 * @brief Enable/disable the sleep status interrupt on INT_1
1037 * @param[in] sensorInterface Pointer to sensor interface
1038 * @param[in] int1SleepStatus Sleep status interrupt enable state
1039 * @retval Error code
1040 */
ITDS_enableSleepStatusINT1(WE_sensorInterface_t * sensorInterface,ITDS_state_t int1SleepStatus)1041 int8_t ITDS_enableSleepStatusINT1(WE_sensorInterface_t* sensorInterface, ITDS_state_t int1SleepStatus)
1042 {
1043 ITDS_ctrl5_t ctrl5;
1044
1045 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_5_REG, 1, (uint8_t *) &ctrl5))
1046 {
1047 return WE_FAIL;
1048 }
1049
1050 ctrl5.sleepStateINT1 = int1SleepStatus;
1051
1052 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_5_REG, 1, (uint8_t *) &ctrl5);
1053 }
1054
1055 /**
1056 * @brief Check if the sleep status interrupt on INT_1 is enabled
1057 * @param[in] sensorInterface Pointer to sensor interface
1058 * @param[out] int1SleepStatus The returned sleep status interrupt enable state
1059 * @retval Error code
1060 */
ITDS_isSleepStatusINT1Enabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * int1SleepStatus)1061 int8_t ITDS_isSleepStatusINT1Enabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *int1SleepStatus)
1062 {
1063 ITDS_ctrl5_t ctrl5;
1064
1065 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_5_REG, 1, (uint8_t *) &ctrl5))
1066 {
1067 return WE_FAIL;
1068 }
1069
1070 *int1SleepStatus = (ITDS_state_t) ctrl5.sleepStateINT1;
1071
1072 return WE_SUCCESS;
1073 }
1074
1075 /**
1076 * @brief Enable/disable the sleep status change interrupt on INT_1
1077 * (signaling transition from active to inactive and vice versa)
1078 *
1079 * @param[in] sensorInterface Pointer to sensor interface
1080 * @param[in] int1SleepChange Sleep status change signal on INT_1
1081 * @retval Error code
1082 */
ITDS_enableSleepStatusChangeINT1(WE_sensorInterface_t * sensorInterface,ITDS_state_t int1SleepChange)1083 int8_t ITDS_enableSleepStatusChangeINT1(WE_sensorInterface_t* sensorInterface, ITDS_state_t int1SleepChange)
1084 {
1085 ITDS_ctrl5_t ctrl5;
1086
1087 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_5_REG, 1, (uint8_t *) &ctrl5))
1088 {
1089 return WE_FAIL;
1090 }
1091
1092 ctrl5.sleepStatusChangeINT1 = int1SleepChange;
1093
1094 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_5_REG, 1, (uint8_t *) &ctrl5);
1095 }
1096
1097 /**
1098 * @brief Check if the sleep status change interrupt on INT_1 is enabled
1099 * (signaling transition from active to inactive and vice versa)
1100 *
1101 * @param[in] sensorInterface Pointer to sensor interface
1102 * @param[out] int1SleepChange The returned sleep status change interrupt state
1103 * @retval Error code
1104 */
ITDS_isSleepStatusChangeINT1Enabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * int1SleepChange)1105 int8_t ITDS_isSleepStatusChangeINT1Enabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *int1SleepChange)
1106 {
1107 ITDS_ctrl5_t ctrl5;
1108
1109 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_5_REG, 1, (uint8_t *) &ctrl5))
1110 {
1111 return WE_FAIL;
1112 }
1113
1114 *int1SleepChange = (ITDS_state_t) ctrl5.sleepStatusChangeINT1;
1115
1116 return WE_SUCCESS;
1117 }
1118
1119 /**
1120 * @brief Enable/disable the boot interrupt on INT_1
1121 * @param[in] sensorInterface Pointer to sensor interface
1122 * @param[in] int1Boot Boot interrupt enable state
1123 * @retval Error code
1124 */
ITDS_enableBootStatusINT1(WE_sensorInterface_t * sensorInterface,ITDS_state_t int1Boot)1125 int8_t ITDS_enableBootStatusINT1(WE_sensorInterface_t* sensorInterface, ITDS_state_t int1Boot)
1126 {
1127 ITDS_ctrl5_t ctrl5;
1128
1129 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_5_REG, 1, (uint8_t *) &ctrl5))
1130 {
1131 return WE_FAIL;
1132 }
1133
1134 ctrl5.bootStatusINT1 = int1Boot;
1135
1136 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_5_REG, 1, (uint8_t *) &ctrl5);
1137 }
1138
1139 /**
1140 * @brief Check if the boot interrupt on INT_1 is enabled
1141 * @param[in] sensorInterface Pointer to sensor interface
1142 * @param[out] int1Boot The returned boot interrupt enable state
1143 * @retval Error code
1144 */
ITDS_isBootStatusINT1Enabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * int1Boot)1145 int8_t ITDS_isBootStatusINT1Enabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *int1Boot)
1146 {
1147 ITDS_ctrl5_t ctrl5;
1148
1149 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_5_REG, 1, (uint8_t *) &ctrl5))
1150 {
1151 return WE_FAIL;
1152 }
1153
1154 *int1Boot = (ITDS_state_t) ctrl5.bootStatusINT1;
1155
1156 return WE_SUCCESS;
1157 }
1158
1159 /**
1160 * @brief Enable/disable the temperature data-ready interrupt on INT_1
1161 * @param[in] sensorInterface Pointer to sensor interface
1162 * @param[in] int1TempDataReady The temperature data-ready interrupt enable state
1163 * @retval Error code
1164 */
ITDS_enableTempDataReadyINT1(WE_sensorInterface_t * sensorInterface,ITDS_state_t int1TempDataReady)1165 int8_t ITDS_enableTempDataReadyINT1(WE_sensorInterface_t* sensorInterface, ITDS_state_t int1TempDataReady)
1166 {
1167 ITDS_ctrl5_t ctrl5;
1168
1169 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_5_REG, 1, (uint8_t *) &ctrl5))
1170 {
1171 return WE_FAIL;
1172 }
1173
1174 ctrl5.tempDataReadyINT1 = int1TempDataReady;
1175
1176 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_5_REG, 1, (uint8_t *) &ctrl5);
1177 }
1178
1179 /**
1180 * @brief Check if the temperature data-ready interrupt on INT_1 is enabled
1181 * @param[in] sensorInterface Pointer to sensor interface
1182 * @param[out] int1TempDataReady The returned temperature data-ready interrupt enable state
1183 * @retval Error code
1184 */
ITDS_isTempDataReadyINT1Enabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * int1TempDataReady)1185 int8_t ITDS_isTempDataReadyINT1Enabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *int1TempDataReady)
1186 {
1187 ITDS_ctrl5_t ctrl5;
1188
1189 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_5_REG, 1, (uint8_t *) &ctrl5))
1190 {
1191 return WE_FAIL;
1192 }
1193
1194 *int1TempDataReady = (ITDS_state_t) ctrl5.tempDataReadyINT1;
1195
1196 return WE_SUCCESS;
1197 }
1198
1199 /**
1200 * @brief Enable/disable the FIFO overrun interrupt on INT_1
1201 * @param[in] sensorInterface Pointer to sensor interface
1202 * @param[in] int1FifoOverrun FIFO overrun interrupt enable state
1203 * @retval Error code
1204 */
ITDS_enableFifoOverrunIntINT1(WE_sensorInterface_t * sensorInterface,ITDS_state_t int1FifoOverrun)1205 int8_t ITDS_enableFifoOverrunIntINT1(WE_sensorInterface_t* sensorInterface, ITDS_state_t int1FifoOverrun)
1206 {
1207 ITDS_ctrl5_t ctrl5;
1208
1209 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_5_REG, 1, (uint8_t *) &ctrl5))
1210 {
1211 return WE_FAIL;
1212 }
1213
1214 ctrl5.fifoOverrunINT1 = int1FifoOverrun;
1215
1216 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_5_REG, 1, (uint8_t *) &ctrl5);
1217 }
1218
1219 /**
1220 * @brief Check if the FIFO overrun interrupt on INT_1 is enabled
1221 * @param[in] sensorInterface Pointer to sensor interface
1222 * @param[out] int1FifoOverrun The returned FIFO overrun interrupt enable state
1223 * @retval Error code
1224 */
ITDS_isFifoOverrunIntINT1Enabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * int1FifoOverrun)1225 int8_t ITDS_isFifoOverrunIntINT1Enabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *int1FifoOverrun)
1226 {
1227 ITDS_ctrl5_t ctrl5;
1228
1229 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_5_REG, 1, (uint8_t *) &ctrl5))
1230 {
1231 return WE_FAIL;
1232 }
1233
1234 *int1FifoOverrun = (ITDS_state_t) ctrl5.fifoOverrunINT1;
1235 return WE_SUCCESS;
1236 }
1237
1238 /**
1239 * @brief Enable/disable the FIFO full interrupt on INT_1
1240 * @param[in] sensorInterface Pointer to sensor interface
1241 * @param[in] int1FifoFull FIFO full interrupt enable state
1242 * @retval Error code
1243 */
ITDS_enableFifoFullINT1(WE_sensorInterface_t * sensorInterface,ITDS_state_t int1FifoFull)1244 int8_t ITDS_enableFifoFullINT1(WE_sensorInterface_t* sensorInterface, ITDS_state_t int1FifoFull)
1245 {
1246 ITDS_ctrl5_t ctrl5;
1247
1248 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_5_REG, 1, (uint8_t *) &ctrl5))
1249 {
1250 return WE_FAIL;
1251 }
1252
1253 ctrl5.fifoFullINT1 = int1FifoFull;
1254
1255 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_5_REG, 1, (uint8_t *) &ctrl5);
1256 }
1257
1258 /**
1259 * @brief Check if the FIFO full interrupt on INT_1 is enabled
1260 * @param[in] sensorInterface Pointer to sensor interface
1261 * @param[out] int1FifoFull The returned FIFO full interrupt enable state
1262 * @retval Error code
1263 */
ITDS_isFifoFullINT1Enabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * int1FifoFull)1264 int8_t ITDS_isFifoFullINT1Enabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *int1FifoFull)
1265 {
1266 ITDS_ctrl5_t ctrl5;
1267
1268 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_5_REG, 1, (uint8_t *) &ctrl5))
1269 {
1270 return WE_FAIL;
1271 }
1272
1273 *int1FifoFull = (ITDS_state_t) ctrl5.fifoFullINT1;
1274
1275 return WE_SUCCESS;
1276 }
1277
1278 /**
1279 * @brief Enable/disable the FIFO threshold interrupt on INT_1
1280 * @param[in] sensorInterface Pointer to sensor interface
1281 * @param[in] int1FifoThresholdInt FIFO threshold interrupt enable state
1282 * @retval Error code
1283 */
ITDS_enableFifoThresholdINT1(WE_sensorInterface_t * sensorInterface,ITDS_state_t int1FifoThresholdInt)1284 int8_t ITDS_enableFifoThresholdINT1(WE_sensorInterface_t* sensorInterface, ITDS_state_t int1FifoThresholdInt)
1285 {
1286 ITDS_ctrl5_t ctrl5;
1287
1288 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_5_REG, 1, (uint8_t *) &ctrl5))
1289 {
1290 return WE_FAIL;
1291 }
1292
1293 ctrl5.fifoThresholdINT1 = int1FifoThresholdInt;
1294
1295 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_5_REG, 1, (uint8_t *) &ctrl5);
1296 }
1297
1298 /**
1299 * @brief Check if the FIFO threshold interrupt on INT_1 is enabled
1300 * @param[in] sensorInterface Pointer to sensor interface
1301 * @param[out] int1FifoThresholdInt The returned FIFO threshold interrupt enable state
1302 * @retval Error code
1303 */
ITDS_isFifoThresholdINT1Enabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * int1FifoThresholdInt)1304 int8_t ITDS_isFifoThresholdINT1Enabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *int1FifoThresholdInt)
1305 {
1306 ITDS_ctrl5_t ctrl5;
1307
1308 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_5_REG, 1, (uint8_t *) &ctrl5))
1309 {
1310 return WE_FAIL;
1311 }
1312
1313 *int1FifoThresholdInt = (ITDS_state_t) ctrl5.fifoThresholdINT1;
1314 return WE_SUCCESS;
1315 }
1316
1317 /**
1318 * @brief Enable/disable the data-ready interrupt on INT_1
1319 * @param[in] sensorInterface Pointer to sensor interface
1320 * @param[in] int1DataReadyInt Data-ready interrupt enable state
1321 * @retval Error code
1322 */
ITDS_enableDataReadyINT1(WE_sensorInterface_t * sensorInterface,ITDS_state_t int1DataReadyInt)1323 int8_t ITDS_enableDataReadyINT1(WE_sensorInterface_t* sensorInterface, ITDS_state_t int1DataReadyInt)
1324 {
1325 ITDS_ctrl5_t ctrl5;
1326
1327 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_5_REG, 1, (uint8_t *) &ctrl5))
1328 {
1329 return WE_FAIL;
1330 }
1331
1332 ctrl5.dataReadyINT1 = int1DataReadyInt;
1333
1334 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_5_REG, 1, (uint8_t *) &ctrl5);
1335 }
1336
1337 /**
1338 * @brief Check if the data-ready interrupt on INT_1 is enabled
1339 * @param[in] sensorInterface Pointer to sensor interface
1340 * @param[out] int1DataReadyInt The returned data-ready interrupt enable state
1341 * @retval Error code
1342 */
ITDS_isDataReadyINT1Enabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * int1DataReadyInt)1343 int8_t ITDS_isDataReadyINT1Enabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *int1DataReadyInt)
1344 {
1345 ITDS_ctrl5_t ctrl5;
1346
1347 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_5_REG, 1, (uint8_t *) &ctrl5))
1348 {
1349 return WE_FAIL;
1350 }
1351
1352 *int1DataReadyInt = (ITDS_state_t) ctrl5.dataReadyINT1;
1353
1354 return WE_SUCCESS;
1355 }
1356
1357
1358 /* CTRL REG 6 */
1359
1360 /**
1361 * @brief Set the filtering cut-off
1362 * @param[in] sensorInterface Pointer to sensor interface
1363 * @param[in] filteringCutoff Filtering cut-off
1364 * @retval Error code
1365 */
ITDS_setFilteringCutoff(WE_sensorInterface_t * sensorInterface,ITDS_bandwidth_t filteringCutoff)1366 int8_t ITDS_setFilteringCutoff(WE_sensorInterface_t* sensorInterface, ITDS_bandwidth_t filteringCutoff)
1367 {
1368 ITDS_ctrl6_t ctrl6;
1369
1370 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_6_REG, 1, (uint8_t *) &ctrl6))
1371 {
1372 return WE_FAIL;
1373 }
1374
1375 ctrl6.filterBandwidth = filteringCutoff;
1376
1377 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_6_REG, 1, (uint8_t *) &ctrl6);
1378 }
1379
1380 /**
1381 * @brief Read filtering cut-off
1382 * @param[in] sensorInterface Pointer to sensor interface
1383 * @param[out] filteringCutoff The returned filtering cut-off
1384 * @retval Error code
1385 */
ITDS_getFilteringCutoff(WE_sensorInterface_t * sensorInterface,ITDS_bandwidth_t * filteringCutoff)1386 int8_t ITDS_getFilteringCutoff(WE_sensorInterface_t* sensorInterface, ITDS_bandwidth_t *filteringCutoff)
1387 {
1388 ITDS_ctrl6_t ctrl6;
1389
1390 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_6_REG, 1, (uint8_t *) &ctrl6))
1391 {
1392 return WE_FAIL;
1393 }
1394
1395 *filteringCutoff = (ITDS_bandwidth_t) ctrl6.filterBandwidth;
1396
1397 return WE_SUCCESS;
1398 }
1399
1400 /**
1401 * @brief Set the full scale
1402 * @param[in] sensorInterface Pointer to sensor interface
1403 * @param[in] fullScale Full scale
1404 * @retval Error code
1405 */
ITDS_setFullScale(WE_sensorInterface_t * sensorInterface,ITDS_fullScale_t fullScale)1406 int8_t ITDS_setFullScale(WE_sensorInterface_t* sensorInterface, ITDS_fullScale_t fullScale)
1407 {
1408 ITDS_ctrl6_t ctrl6;
1409
1410 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_6_REG, 1, (uint8_t *) &ctrl6))
1411 {
1412 return WE_FAIL;
1413 }
1414
1415 ctrl6.fullScale = fullScale;
1416
1417 int8_t errCode = ITDS_WriteReg(sensorInterface, ITDS_CTRL_6_REG, 1, (uint8_t *) &ctrl6);
1418
1419 /* Store current full scale value to allow convenient conversion of sensor readings */
1420 if (WE_SUCCESS == errCode)
1421 {
1422 currentFullScale = fullScale;
1423 }
1424
1425 return errCode;
1426 }
1427
1428 /**
1429 * @brief Read the full scale
1430 * @param[in] sensorInterface Pointer to sensor interface
1431 * @param[out] fullScale The returned full scale.
1432 * @retval Error code
1433 */
ITDS_getFullScale(WE_sensorInterface_t * sensorInterface,ITDS_fullScale_t * fullScale)1434 int8_t ITDS_getFullScale(WE_sensorInterface_t* sensorInterface, ITDS_fullScale_t *fullScale)
1435 {
1436 ITDS_ctrl6_t ctrl6;
1437
1438 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_6_REG, 1, (uint8_t *) &ctrl6))
1439 {
1440 return WE_FAIL;
1441 }
1442
1443 *fullScale = (ITDS_fullScale_t) ctrl6.fullScale;
1444
1445 /* Store current full scale value to allow convenient conversion of sensor readings */
1446 currentFullScale = *fullScale;
1447
1448 return WE_SUCCESS;
1449 }
1450
1451 /**
1452 * @brief Set the filter type [low-pass filter/high-pass filter]
1453 * @param[in] sensorInterface Pointer to sensor interface
1454 * @param[in] filterType Filter Type
1455 * @retval Error code
1456 */
ITDS_setFilterPath(WE_sensorInterface_t * sensorInterface,ITDS_filterType_t filterType)1457 int8_t ITDS_setFilterPath(WE_sensorInterface_t* sensorInterface, ITDS_filterType_t filterType)
1458 {
1459 ITDS_ctrl6_t ctrl6;
1460
1461 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_6_REG, 1, (uint8_t *) &ctrl6))
1462 {
1463 return WE_FAIL;
1464 }
1465
1466 ctrl6.filterPath = filterType;
1467
1468 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_6_REG, 1, (uint8_t *) &ctrl6);
1469 }
1470
1471 /**
1472 * @brief Read the filter type
1473 * @param[in] sensorInterface Pointer to sensor interface
1474 * @param[out] filterType The returned filter type
1475 * @retval Error code
1476 */
ITDS_getFilterPath(WE_sensorInterface_t * sensorInterface,ITDS_filterType_t * filterType)1477 int8_t ITDS_getFilterPath(WE_sensorInterface_t* sensorInterface, ITDS_filterType_t *filterType)
1478 {
1479 ITDS_ctrl6_t ctrl6;
1480
1481 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_6_REG, 1, (uint8_t *) &ctrl6))
1482 {
1483 return WE_FAIL;
1484 }
1485
1486 *filterType = (ITDS_filterType_t) ctrl6.filterPath;
1487
1488 return WE_SUCCESS;
1489 }
1490
1491 /**
1492 * @brief Enable/disable the low noise configuration
1493 * @param[in] sensorInterface Pointer to sensor interface
1494 * @param[in] lowNoise Low noise configuration
1495 * @retval Error code
1496 */
ITDS_enableLowNoise(WE_sensorInterface_t * sensorInterface,ITDS_state_t lowNoise)1497 int8_t ITDS_enableLowNoise(WE_sensorInterface_t* sensorInterface, ITDS_state_t lowNoise)
1498 {
1499 ITDS_ctrl6_t ctrl6;
1500
1501 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_6_REG, 1, (uint8_t *) &ctrl6))
1502 {
1503 return WE_FAIL;
1504 }
1505
1506 ctrl6.enLowNoise = lowNoise;
1507
1508 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_6_REG, 1, (uint8_t *) &ctrl6);
1509 }
1510
1511 /**
1512 * @brief Read the low noise configuration
1513 * @param[in] sensorInterface Pointer to sensor interface
1514 * @param[out] lowNoise The returned low noise configuration
1515 * @retval Error code
1516 */
ITDS_isLowNoiseEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * lowNoise)1517 int8_t ITDS_isLowNoiseEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *lowNoise)
1518 {
1519 ITDS_ctrl6_t ctrl6;
1520
1521 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_6_REG, 1, (uint8_t *) &ctrl6))
1522 {
1523 return WE_FAIL;
1524 }
1525
1526 *lowNoise = (ITDS_state_t) ctrl6.enLowNoise;
1527
1528 return WE_SUCCESS;
1529 }
1530
1531
1532 /* STATUS REG 0x27 */
1533 /* Note: The status register is partially duplicated to the STATUS_DETECT register. */
1534
1535 /**
1536 * @brief Get overall sensor event status
1537 * @param[in] sensorInterface Pointer to sensor interface
1538 * @param[out] status The returned sensor event data
1539 * @retval Error code
1540 */
ITDS_getStatusRegister(WE_sensorInterface_t * sensorInterface,ITDS_status_t * status)1541 int8_t ITDS_getStatusRegister(WE_sensorInterface_t* sensorInterface, ITDS_status_t *status)
1542 {
1543 return ITDS_ReadReg(sensorInterface, ITDS_STATUS_REG, 1, (uint8_t *) status);
1544 }
1545
1546 /**
1547 * @brief Check if new acceleration samples are available.
1548 * @param[in] sensorInterface Pointer to sensor interface
1549 * @param[out] dataReady The returned data-ready state.
1550 * @retval Error code
1551 */
ITDS_isAccelerationDataReady(WE_sensorInterface_t * sensorInterface,ITDS_state_t * dataReady)1552 int8_t ITDS_isAccelerationDataReady(WE_sensorInterface_t* sensorInterface, ITDS_state_t *dataReady)
1553 {
1554 ITDS_status_t statusRegister;
1555
1556 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_STATUS_REG, 1, (uint8_t *) &statusRegister))
1557 {
1558 return WE_FAIL;
1559 }
1560
1561 *dataReady = (ITDS_state_t) statusRegister.dataReady;
1562
1563 return WE_SUCCESS;
1564 }
1565
1566 /**
1567 * @brief Read the single-tap event state [not detected/detected]
1568 * @param[in] sensorInterface Pointer to sensor interface
1569 * @param[out] singleTap The returned single-tap event state.
1570 * @retval Error code
1571 */
ITDS_getSingleTapState(WE_sensorInterface_t * sensorInterface,ITDS_state_t * singleTap)1572 int8_t ITDS_getSingleTapState(WE_sensorInterface_t* sensorInterface, ITDS_state_t *singleTap)
1573 {
1574 ITDS_status_t statusRegister;
1575
1576 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_STATUS_REG, 1, (uint8_t *) &statusRegister))
1577 {
1578 return WE_FAIL;
1579 }
1580
1581 *singleTap = (ITDS_state_t) statusRegister.singleTap;
1582
1583 return WE_SUCCESS;
1584 }
1585
1586 /**
1587 * @brief Read the double-tap event state [not detected/detected]
1588 * @param[in] sensorInterface Pointer to sensor interface
1589 * @param[out] doubleTap The returned double-tap event state
1590 * @retval Error code
1591 */
ITDS_getDoubleTapState(WE_sensorInterface_t * sensorInterface,ITDS_state_t * doubleTap)1592 int8_t ITDS_getDoubleTapState(WE_sensorInterface_t* sensorInterface, ITDS_state_t *doubleTap)
1593 {
1594 ITDS_status_t statusRegister;
1595
1596 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_STATUS_REG, 1, (uint8_t *) &statusRegister))
1597 {
1598 return WE_FAIL;
1599 }
1600
1601 *doubleTap = (ITDS_state_t) statusRegister.doubleTap;
1602
1603 return WE_SUCCESS;
1604 }
1605
1606 /**
1607 * @brief Read the sleep state [not sleeping/sleeping]
1608 * @param[in] sensorInterface Pointer to sensor interface
1609 * @param[out] sleepState The returned sleep state.
1610 * @retval Error code
1611 */
ITDS_getSleepState(WE_sensorInterface_t * sensorInterface,ITDS_state_t * sleepState)1612 int8_t ITDS_getSleepState(WE_sensorInterface_t* sensorInterface, ITDS_state_t *sleepState)
1613 {
1614 ITDS_status_t statusRegister;
1615
1616 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_STATUS_REG, 1, (uint8_t *) &statusRegister))
1617 {
1618 return WE_FAIL;
1619 }
1620
1621 *sleepState = (ITDS_state_t) statusRegister.sleepState;
1622
1623 return WE_SUCCESS;
1624 }
1625
1626
1627 /* X_OUT_L_REG */
1628
1629 /**
1630 * @brief Read the raw X-axis acceleration sensor output
1631 *
1632 * This function expects that BDU (block data update) and Auto Increment are enabled, e.g. by using:
1633 * ITDS_enableAutoIncrement(), ITDS_enableBlockDataUpdate() functions provided by this SDK.
1634 *
1635 * @param[in] sensorInterface Pointer to sensor interface
1636 * @param[out] xRawAcc The returned raw X-axis acceleration
1637 * @retval Error code
1638 */
ITDS_getRawAccelerationX(WE_sensorInterface_t * sensorInterface,int16_t * xRawAcc)1639 int8_t ITDS_getRawAccelerationX(WE_sensorInterface_t* sensorInterface, int16_t *xRawAcc)
1640 {
1641 int16_t xAxisAccelerationRaw = 0;
1642 uint8_t tmp[2] = {0};
1643
1644 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_X_OUT_L_REG, 2, tmp))
1645 {
1646 return WE_FAIL;
1647 }
1648
1649 xAxisAccelerationRaw = (int16_t) (tmp[1] << 8);
1650 xAxisAccelerationRaw |= (int16_t) tmp[0];
1651
1652 *xRawAcc = xAxisAccelerationRaw;
1653 return WE_SUCCESS;
1654 }
1655
1656
1657 /* Y_OUT_L_REG */
1658
1659 /**
1660 * @brief Read the raw Y-axis acceleration sensor output
1661 *
1662 * This function expects that BDU (block data update) and Auto Increment are enabled, e.g. by using:
1663 * ITDS_enableAutoIncrement(), ITDS_enableBlockDataUpdate() functions provided by this SDK.
1664 *
1665 * @param[in] sensorInterface Pointer to sensor interface
1666 * @param[out] yRawAcc The returned raw Y-axis acceleration
1667 * @retval Error code
1668 */
ITDS_getRawAccelerationY(WE_sensorInterface_t * sensorInterface,int16_t * yRawAcc)1669 int8_t ITDS_getRawAccelerationY(WE_sensorInterface_t* sensorInterface, int16_t *yRawAcc)
1670 {
1671 int16_t yAxisAccelerationRaw = 0;
1672 uint8_t tmp[2] = {0};
1673
1674 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_Y_OUT_L_REG, 2, tmp))
1675 {
1676 return WE_FAIL;
1677 }
1678
1679 yAxisAccelerationRaw = (int16_t) (tmp[1] << 8);
1680 yAxisAccelerationRaw |= (int16_t) tmp[0];
1681
1682 *yRawAcc = yAxisAccelerationRaw;
1683 return WE_SUCCESS;
1684 }
1685
1686
1687 /* Z_OUT_L_REG */
1688
1689 /**
1690 * @brief Read the raw Z-axis acceleration sensor output
1691 *
1692 * This function expects that BDU (block data update) and Auto Increment are enabled, e.g. by using:
1693 * ITDS_enableAutoIncrement(), ITDS_enableBlockDataUpdate() functions provided by this SDK.
1694 *
1695 * @param[in] sensorInterface Pointer to sensor interface
1696 * @param[out] zRawAcc The returned raw Z-axis acceleration
1697 * @retval Error code
1698 */
ITDS_getRawAccelerationZ(WE_sensorInterface_t * sensorInterface,int16_t * zRawAcc)1699 int8_t ITDS_getRawAccelerationZ(WE_sensorInterface_t* sensorInterface, int16_t *zRawAcc)
1700 {
1701 int16_t zAxisAccelerationRaw = 0;
1702 uint8_t tmp[2] = {0};
1703
1704 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_Z_OUT_L_REG, 2, tmp))
1705 {
1706 return WE_FAIL;
1707 }
1708
1709 zAxisAccelerationRaw = (int16_t) (tmp[1] << 8);
1710 zAxisAccelerationRaw |= (int16_t) tmp[0];
1711
1712 *zRawAcc = zAxisAccelerationRaw;
1713 return WE_SUCCESS;
1714 }
1715
1716
1717 /**
1718 * @brief Returns one or more acceleration samples (raw) for all axes.
1719 *
1720 * This function expects that BDU (block data update) and Auto Increment are enabled, e.g. by using:
1721 * ITDS_enableAutoIncrement(), ITDS_enableBlockDataUpdate() functions provided by this SDK.
1722 *
1723 * @param[in] sensorInterface Pointer to sensor interface
1724 * @param[in] numSamples Number of samples to be read (1-32)
1725 * @param[out] xRawAcc X-axis raw acceleration
1726 * @param[out] yRawAcc Y-axis raw acceleration
1727 * @param[out] zRawAcc Z-axis raw acceleration
1728 * @retval Error code
1729 */
ITDS_getRawAccelerations(WE_sensorInterface_t * sensorInterface,uint8_t numSamples,int16_t * xRawAcc,int16_t * yRawAcc,int16_t * zRawAcc)1730 int8_t ITDS_getRawAccelerations(WE_sensorInterface_t* sensorInterface,
1731 uint8_t numSamples,
1732 int16_t *xRawAcc,
1733 int16_t *yRawAcc,
1734 int16_t *zRawAcc)
1735 {
1736 /* Max. buffer size is 192 (32 slot, 16 bit values) */
1737 uint8_t buffer[192];
1738
1739 if (numSamples > 32)
1740 {
1741 return WE_FAIL;
1742 }
1743
1744 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_X_OUT_L_REG, 3 * 2 * numSamples, buffer))
1745 {
1746 return WE_FAIL;
1747 }
1748
1749 int16_t sample;
1750 uint8_t *bufferPtr = buffer;
1751 for (uint8_t i = 0; i < numSamples; i++)
1752 {
1753 sample = ((int16_t) *bufferPtr);
1754 bufferPtr++;
1755 sample |= (int16_t) ((*bufferPtr) << 8);
1756 bufferPtr++;
1757 xRawAcc[i] = sample;
1758
1759 sample = ((int16_t) *bufferPtr);
1760 bufferPtr++;
1761 sample |= (int16_t) ((*bufferPtr) << 8);
1762 bufferPtr++;
1763 yRawAcc[i] = sample;
1764
1765 sample = ((int16_t) *bufferPtr);
1766 bufferPtr++;
1767 sample |= (int16_t) ((*bufferPtr) << 8);
1768 bufferPtr++;
1769 zRawAcc[i] = sample;
1770 }
1771
1772 return WE_SUCCESS;
1773 }
1774
1775 /**
1776 * @brief Reads the X axis acceleration in [mg].
1777 *
1778 * Note that this functions relies on the current full scale value.
1779 * Make sure that the current full scale value is known by calling
1780 * ITDS_setFullScale() or ITDS_getFullScale() at least once prior to
1781 * calling this function.
1782 *
1783 * @param[in] sensorInterface Pointer to sensor interface
1784 * @param[out] xAcc X axis acceleration value in [mg]
1785 * @retval Error code
1786 */
ITDS_getAccelerationX_float(WE_sensorInterface_t * sensorInterface,float * xAcc)1787 int8_t ITDS_getAccelerationX_float(WE_sensorInterface_t* sensorInterface, float *xAcc)
1788 {
1789 int16_t rawAcc;
1790 if (WE_FAIL == ITDS_getRawAccelerationX(sensorInterface, &rawAcc))
1791 {
1792 return WE_FAIL;
1793 }
1794 *xAcc = ITDS_convertAcceleration_float(rawAcc, currentFullScale);
1795 return WE_SUCCESS;
1796 }
1797
1798 /**
1799 * @brief Reads the Y axis acceleration in [mg].
1800 *
1801 * Note that this functions relies on the current full scale value.
1802 * Make sure that the current full scale value is known by calling
1803 * ITDS_setFullScale() or ITDS_getFullScale() at least once prior to
1804 * calling this function.
1805 *
1806 * @param[in] sensorInterface Pointer to sensor interface
1807 * @param[out] yAcc Y axis acceleration value in [mg]
1808 * @retval Error code
1809 */
ITDS_getAccelerationY_float(WE_sensorInterface_t * sensorInterface,float * yAcc)1810 int8_t ITDS_getAccelerationY_float(WE_sensorInterface_t* sensorInterface, float *yAcc)
1811 {
1812 int16_t rawAcc;
1813 if (WE_FAIL == ITDS_getRawAccelerationY(sensorInterface, &rawAcc))
1814 {
1815 return WE_FAIL;
1816 }
1817 *yAcc = ITDS_convertAcceleration_float(rawAcc, currentFullScale);
1818 return WE_SUCCESS;
1819 }
1820
1821 /**
1822 * @brief Reads the Z axis acceleration in [mg].
1823 *
1824 * Note that this functions relies on the current full scale value.
1825 * Make sure that the current full scale value is known by calling
1826 * ITDS_setFullScale() or ITDS_getFullScale() at least once prior to
1827 * calling this function.
1828 *
1829 * @param[in] sensorInterface Pointer to sensor interface
1830 * @param[out] zAcc Z axis acceleration value in [mg]
1831 * @retval Error code
1832 */
ITDS_getAccelerationZ_float(WE_sensorInterface_t * sensorInterface,float * zAcc)1833 int8_t ITDS_getAccelerationZ_float(WE_sensorInterface_t* sensorInterface, float *zAcc)
1834 {
1835 int16_t rawAcc;
1836 if (WE_FAIL == ITDS_getRawAccelerationZ(sensorInterface, &rawAcc))
1837 {
1838 return WE_FAIL;
1839 }
1840 *zAcc = ITDS_convertAcceleration_float(rawAcc, currentFullScale);
1841 return WE_SUCCESS;
1842 }
1843
1844 /**
1845 * @brief Returns one or more acceleration samples in [mg] for all axes.
1846 *
1847 * Note that this functions relies on the current full scale value.
1848 * Make sure that the current full scale value is known by calling
1849 * ITDS_setFullScale() or ITDS_getFullScale() at least once prior to
1850 * calling this function.
1851 *
1852 * @param[in] sensorInterface Pointer to sensor interface
1853 * @param[in] numSamples Number of samples to be read (1-32)
1854 * @param[out] xAcc X-axis acceleration in [mg]
1855 * @param[out] yAcc Y-axis acceleration in [mg]
1856 * @param[out] zAcc Z-axis acceleration in [mg]
1857 * @retval Error code
1858 */
ITDS_getAccelerations_float(WE_sensorInterface_t * sensorInterface,uint8_t numSamples,float * xAcc,float * yAcc,float * zAcc)1859 int8_t ITDS_getAccelerations_float(WE_sensorInterface_t* sensorInterface,
1860 uint8_t numSamples,
1861 float *xAcc,
1862 float *yAcc,
1863 float *zAcc)
1864 {
1865 /* Max. buffer size is 192 (32 slot, 16 bit values) */
1866 uint8_t buffer[192];
1867
1868 if (numSamples > 32)
1869 {
1870 return WE_FAIL;
1871 }
1872
1873 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_X_OUT_L_REG, 3 * 2 * numSamples, buffer))
1874 {
1875 return WE_FAIL;
1876 }
1877
1878 uint16_t sample;
1879 uint8_t *bufferPtr = buffer;
1880 for (uint8_t i = 0; i < numSamples; i++)
1881 {
1882 sample = ((int16_t) *bufferPtr);
1883 bufferPtr++;
1884 sample |= (int16_t) ((*bufferPtr) << 8);
1885 bufferPtr++;
1886 xAcc[i] = ITDS_convertAcceleration_float((int16_t) sample, currentFullScale);
1887
1888 sample = ((int16_t) *bufferPtr);
1889 bufferPtr++;
1890 sample |= (int16_t) ((*bufferPtr) << 8);
1891 bufferPtr++;
1892 yAcc[i] = ITDS_convertAcceleration_float((int16_t) sample, currentFullScale);
1893
1894 sample = ((int16_t) *bufferPtr);
1895 bufferPtr++;
1896 sample |= (int16_t) ((*bufferPtr) << 8);
1897 bufferPtr++;
1898 zAcc[i] = ITDS_convertAcceleration_float((int16_t) sample, currentFullScale);
1899 }
1900
1901 return WE_SUCCESS;
1902 }
1903
1904 /**
1905 * @brief Converts the supplied raw acceleration into [mg]
1906 * @param[in] acc Raw acceleration value (accelerometer output)
1907 * @param[in] fullScale Accelerometer full scale
1908 * @retval The converted acceleration in [mg]
1909 */
ITDS_convertAcceleration_float(int16_t acc,ITDS_fullScale_t fullScale)1910 float ITDS_convertAcceleration_float(int16_t acc, ITDS_fullScale_t fullScale)
1911 {
1912 switch (fullScale)
1913 {
1914 case ITDS_twoG:
1915 return ITDS_convertAccelerationFs2g_float(acc);
1916
1917 case ITDS_fourG:
1918 return ITDS_convertAccelerationFs4g_float(acc);
1919
1920 case ITDS_eightG:
1921 return ITDS_convertAccelerationFs8g_float(acc);
1922
1923 case ITDS_sixteenG:
1924 return ITDS_convertAccelerationFs16g_float(acc);
1925
1926 default:
1927 break;
1928 }
1929
1930 return 0;
1931 }
1932
1933 /**
1934 * @brief Converts the supplied raw acceleration sampled using
1935 * ITDS_twoG to [mg]
1936 * this operation uses a common factor that already
1937 * includes the shift by 2 (for 14 bit mode) or the shift by 4 (for 12 bit,
1938 * i.e. "low power mode 1") with their respective sensitivity values.
1939 * The applied conversion factor for Full_Scale 2G is valid for
1940 * "low power mode 1" (CTRL_1.LP_Mode = '01') as well as for
1941 * "not low power mode 1" (CTRL_1.LP_Mode != '01') power modes.
1942 *
1943 * @param[in] acc Raw acceleration value (accelerometer output)
1944 * @retval The converted acceleration in [mg]
1945 */
ITDS_convertAccelerationFs2g_float(int16_t acc)1946 float ITDS_convertAccelerationFs2g_float(int16_t acc)
1947 {
1948 return ((float) acc) * 0.061f;
1949 }
1950
1951 /**
1952 * @brief Converts the supplied raw acceleration sampled using
1953 * ITDS_fourG to [mg]
1954 * this operation uses a common factor that already
1955 * includes the shift by 2 (for 14 bit mode) or the shift by 4 (for 12 bit,
1956 * i.e. "low power mode 1") with their respective sensitivity values.
1957 * The applied conversion factor for Full_Scale 4G is valid for
1958 * "low power mode 1" (CTRL_1.LP_Mode = '01') as well as for
1959 * "not low power mode 1" (CTRL_1.LP_Mode != '01') power modes.
1960 *
1961 * @param[in] acc Raw acceleration value (accelerometer output)
1962 * @retval The converted acceleration in [mg]
1963 */
ITDS_convertAccelerationFs4g_float(int16_t acc)1964 float ITDS_convertAccelerationFs4g_float(int16_t acc)
1965 {
1966 return ((float) acc) * 0.122f;
1967 }
1968
1969 /**
1970 * @brief Converts the supplied raw acceleration sampled using
1971 * ITDS_eightG to [mg]
1972 * this operation uses a common factor that already
1973 * includes the shift by 2 (for 14 bit mode) or the shift by 4 (for 12 bit,
1974 * i.e. "low power mode 1") with their respective sensitivity values.
1975 * The applied conversion factor for Full_Scale 8G is valid for
1976 * "low power mode 1" (CTRL_1.LP_Mode = '01') as well as for
1977 * "not low power mode 1" (CTRL_1.LP_Mode != '01') power modes.
1978 *
1979 * @param[in] acc Raw acceleration value (accelerometer output)
1980 * @retval The converted acceleration in [mg]
1981 */
ITDS_convertAccelerationFs8g_float(int16_t acc)1982 float ITDS_convertAccelerationFs8g_float(int16_t acc)
1983 {
1984 return ((float) acc) * 0.244f;
1985 }
1986
1987 /**
1988 * @brief Converts the supplied raw acceleration sampled using
1989 * ITDS_sixteenG to [mg]
1990 * this operation uses a common factor that already
1991 * includes the shift by 2 (for 14 bit mode) or the shift by 4 (for 12 bit,
1992 * i.e. "low power mode 1") with their respective sensitivity values.
1993 * The applied conversion factor for Full_Scale 16G is valid for
1994 * "low power mode 1" (CTRL_1.LP_Mode = '01') as well as for
1995 * "not low power mode 1" (CTRL_1.LP_Mode != '01') power modes.
1996 *
1997 * @param[in] acc Raw acceleration value (accelerometer output)
1998 * @retval The converted acceleration in [mg]
1999 */
ITDS_convertAccelerationFs16g_float(int16_t acc)2000 float ITDS_convertAccelerationFs16g_float(int16_t acc)
2001 {
2002 return ((float) acc) * 0.488f;
2003 }
2004
2005 /**
2006 * @brief Reads the X axis acceleration in [mg].
2007 *
2008 * Note that this functions relies on the current full scale value.
2009 * Make sure that the current full scale value is known by calling
2010 * ITDS_setFullScale() or ITDS_getFullScale() at least once prior to
2011 * calling this function.
2012 *
2013 * @param[in] sensorInterface Pointer to sensor interface
2014 * @param[out] xAcc X axis acceleration value in [mg]
2015 * @retval Error code
2016 */
ITDS_getAccelerationX_int(WE_sensorInterface_t * sensorInterface,int16_t * xAcc)2017 int8_t ITDS_getAccelerationX_int(WE_sensorInterface_t* sensorInterface, int16_t *xAcc)
2018 {
2019 int16_t rawAcc;
2020 if (WE_FAIL == ITDS_getRawAccelerationX(sensorInterface, &rawAcc))
2021 {
2022 return WE_FAIL;
2023 }
2024 *xAcc = ITDS_convertAcceleration_int(rawAcc, currentFullScale);
2025 return WE_SUCCESS;
2026 }
2027
2028 /**
2029 * @brief Reads the Y axis acceleration in [mg].
2030 *
2031 * Note that this functions relies on the current full scale value.
2032 * Make sure that the current full scale value is known by calling
2033 * ITDS_setFullScale() or ITDS_getFullScale() at least once prior to
2034 * calling this function.
2035 *
2036 * @param[in] sensorInterface Pointer to sensor interface
2037 * @param[out] yAcc Y axis acceleration value in [mg]
2038 * @retval Error code
2039 */
ITDS_getAccelerationY_int(WE_sensorInterface_t * sensorInterface,int16_t * yAcc)2040 int8_t ITDS_getAccelerationY_int(WE_sensorInterface_t* sensorInterface, int16_t *yAcc)
2041 {
2042 int16_t rawAcc;
2043 if (WE_FAIL == ITDS_getRawAccelerationY(sensorInterface, &rawAcc))
2044 {
2045 return WE_FAIL;
2046 }
2047 *yAcc = ITDS_convertAcceleration_int(rawAcc, currentFullScale);
2048 return WE_SUCCESS;
2049 }
2050
2051 /**
2052 * @brief Reads the Z axis acceleration in [mg].
2053 *
2054 * Note that this functions relies on the current full scale value.
2055 * Make sure that the current full scale value is known by calling
2056 * ITDS_setFullScale() or ITDS_getFullScale() at least once prior to
2057 * calling this function.
2058 *
2059 * @param[in] sensorInterface Pointer to sensor interface
2060 * @param[out] zAcc Z axis acceleration value in [mg]
2061 * @retval Error code
2062 */
ITDS_getAccelerationZ_int(WE_sensorInterface_t * sensorInterface,int16_t * zAcc)2063 int8_t ITDS_getAccelerationZ_int(WE_sensorInterface_t* sensorInterface, int16_t *zAcc)
2064 {
2065 int16_t rawAcc;
2066 if (WE_FAIL == ITDS_getRawAccelerationZ(sensorInterface, &rawAcc))
2067 {
2068 return WE_FAIL;
2069 }
2070 *zAcc = ITDS_convertAcceleration_int(rawAcc, currentFullScale);
2071 return WE_SUCCESS;
2072 }
2073
2074 /**
2075 * @brief Returns one or more acceleration samples in [mg] for all axes.
2076 *
2077 * Note that this functions relies on the current full scale value.
2078 * Make sure that the current full scale value is known by calling
2079 * ITDS_setFullScale() or ITDS_getFullScale() at least once prior to
2080 * calling this function.
2081 *
2082 * @param[in] sensorInterface Pointer to sensor interface
2083 * @param[in] numSamples Number of samples to be read (1-32)
2084 * @param[out] xAcc X-axis acceleration in [mg]
2085 * @param[out] yAcc Y-axis acceleration in [mg]
2086 * @param[out] zAcc Z-axis acceleration in [mg]
2087 * @retval Error code
2088 */
ITDS_getAccelerations_int(WE_sensorInterface_t * sensorInterface,uint8_t numSamples,int16_t * xAcc,int16_t * yAcc,int16_t * zAcc)2089 int8_t ITDS_getAccelerations_int(WE_sensorInterface_t* sensorInterface,
2090 uint8_t numSamples,
2091 int16_t *xAcc,
2092 int16_t *yAcc,
2093 int16_t *zAcc)
2094 {
2095 /* Max. buffer size is 192 (32 slot, 16 bit values) */
2096 uint8_t buffer[192];
2097
2098 if (numSamples > 32)
2099 {
2100 return WE_FAIL;
2101 }
2102
2103 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_X_OUT_L_REG, 3 * 2 * numSamples, buffer))
2104 {
2105 return WE_FAIL;
2106 }
2107
2108 uint16_t sample;
2109 uint8_t *bufferPtr = buffer;
2110 for (uint8_t i = 0; i < numSamples; i++)
2111 {
2112 sample = ((int16_t) *bufferPtr);
2113 bufferPtr++;
2114 sample |= (int16_t) ((*bufferPtr) << 8);
2115 bufferPtr++;
2116 xAcc[i] = ITDS_convertAcceleration_int((int16_t) sample, currentFullScale);
2117
2118 sample = ((int16_t) *bufferPtr);
2119 bufferPtr++;
2120 sample |= (int16_t) ((*bufferPtr) << 8);
2121 bufferPtr++;
2122 yAcc[i] = ITDS_convertAcceleration_int((int16_t) sample, currentFullScale);
2123
2124 sample = ((int16_t) *bufferPtr);
2125 bufferPtr++;
2126 sample |= (int16_t) ((*bufferPtr) << 8);
2127 bufferPtr++;
2128 zAcc[i] = ITDS_convertAcceleration_int((int16_t) sample, currentFullScale);
2129 }
2130
2131 return WE_SUCCESS;
2132 }
2133
2134 /**
2135 * @brief Converts the supplied raw acceleration into [mg]
2136 * @param[in] acc Raw acceleration value (accelerometer output)
2137 * @param[in] fullScale Accelerometer full scale
2138 * @retval The converted acceleration in [mg]
2139 */
ITDS_convertAcceleration_int(int16_t acc,ITDS_fullScale_t fullScale)2140 int16_t ITDS_convertAcceleration_int(int16_t acc, ITDS_fullScale_t fullScale)
2141 {
2142 switch (fullScale)
2143 {
2144 case ITDS_twoG:
2145 return ITDS_convertAccelerationFs2g_int(acc);
2146
2147 case ITDS_sixteenG:
2148 return ITDS_convertAccelerationFs16g_int(acc);
2149
2150 case ITDS_fourG:
2151 return ITDS_convertAccelerationFs4g_int(acc);
2152
2153 case ITDS_eightG:
2154 return ITDS_convertAccelerationFs8g_int(acc);
2155
2156 default:
2157 return 0;
2158 }
2159 }
2160
2161 /**
2162 * @brief Converts the supplied raw acceleration sampled using
2163 * ITDS_twoG to [mg]
2164 * @param[in] acc Raw acceleration value (accelerometer output)
2165 * @retval The converted acceleration in [mg]
2166 */
ITDS_convertAccelerationFs2g_int(int16_t acc)2167 int16_t ITDS_convertAccelerationFs2g_int(int16_t acc)
2168 {
2169 return (int16_t) ((((int32_t) acc) * 61) / 1000);
2170 }
2171
2172 /**
2173 * @brief Converts the supplied raw acceleration sampled using
2174 * ITDS_fourG to [mg]
2175 * @param[in] acc Raw acceleration value (accelerometer output)
2176 * @retval The converted acceleration in [mg]
2177 */
ITDS_convertAccelerationFs4g_int(int16_t acc)2178 int16_t ITDS_convertAccelerationFs4g_int(int16_t acc)
2179 {
2180 return (int16_t) ((((int32_t) acc) * 122) / 1000);
2181 }
2182
2183 /**
2184 * @brief Converts the supplied raw acceleration sampled using
2185 * ITDS_eightG to [mg]
2186 * @param[in] acc Raw acceleration value (accelerometer output)
2187 * @retval The converted acceleration in [mg]
2188 */
ITDS_convertAccelerationFs8g_int(int16_t acc)2189 int16_t ITDS_convertAccelerationFs8g_int(int16_t acc)
2190 {
2191 return (int16_t) ((((int32_t) acc) * 244) / 1000);
2192 }
2193
2194 /**
2195 * @brief Converts the supplied raw acceleration sampled using
2196 * ITDS_sixteenG to [mg]
2197 * @param[in] acc Raw acceleration value (accelerometer output)
2198 * @retval The converted acceleration in [mg]
2199 */
ITDS_convertAccelerationFs16g_int(int16_t acc)2200 int16_t ITDS_convertAccelerationFs16g_int(int16_t acc)
2201 {
2202 return (int16_t) ((((int32_t) acc) * 488) / 1000);
2203 }
2204
2205
2206 /* ITDS_T_OUT_REG */
2207
2208 /**
2209 * @brief Read the 8 bit temperature
2210 * @param[in] sensorInterface Pointer to sensor interface
2211 * @param[out] temp8bit The returned temperature
2212 * @retval Error code
2213 */
2214
ITDS_getTemperature8bit(WE_sensorInterface_t * sensorInterface,uint8_t * temp8bit)2215 int8_t ITDS_getTemperature8bit(WE_sensorInterface_t* sensorInterface, uint8_t *temp8bit)
2216 {
2217 uint8_t temperatureValue8bit;
2218 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_T_OUT_REG, 1, &temperatureValue8bit))
2219 {
2220 return WE_FAIL;
2221 }
2222
2223 *temp8bit = temperatureValue8bit;
2224 return WE_SUCCESS;
2225 }
2226
2227 /**
2228 * @brief Read the 12 bit temperature
2229 * @param[in] sensorInterface Pointer to sensor interface
2230 * @param[out] temp12bit The returned temperature
2231 * @retval Error code
2232 */
ITDS_getRawTemperature12bit(WE_sensorInterface_t * sensorInterface,int16_t * temp12bit)2233 int8_t ITDS_getRawTemperature12bit(WE_sensorInterface_t* sensorInterface, int16_t *temp12bit)
2234 {
2235 uint8_t temp[2] = {0};
2236
2237 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_T_OUT_L_REG, 2, temp))
2238 {
2239 return WE_FAIL;
2240 }
2241
2242 *temp12bit = (int16_t) (temp[1] << 8);
2243 *temp12bit |= (int16_t) temp[0];
2244
2245 *temp12bit = (*temp12bit) >> 4;
2246
2247 return WE_SUCCESS;
2248 }
2249
2250 /**
2251 * @brief Read the 12 bit temperature in °C
2252 * @param[in] sensorInterface Pointer to sensor interface
2253 * @param[out] tempDegC The returned temperature
2254 * @retval Error code
2255 */
ITDS_getTemperature12bit(WE_sensorInterface_t * sensorInterface,float * tempDegC)2256 int8_t ITDS_getTemperature12bit(WE_sensorInterface_t* sensorInterface, float *tempDegC)
2257 {
2258 int16_t rawTemp = 0;
2259 if (WE_SUCCESS == ITDS_getRawTemperature12bit(sensorInterface, &rawTemp))
2260 {
2261 *tempDegC = (((float) rawTemp) / 16.0f) + 25.0f;
2262 }
2263 else
2264 {
2265 return WE_FAIL;
2266 }
2267 return WE_SUCCESS;
2268 }
2269
2270 /* FIFO_CTRL (0x2E) */
2271
2272 /**
2273 * @brief Set the FIFO threshold of the sensor
2274 * @param[in] sensorInterface Pointer to sensor interface
2275 * @param[in] fifoThreshold FIFO threshold (value between 0 and 31)
2276 * @retval Error code
2277 */
ITDS_setFifoThreshold(WE_sensorInterface_t * sensorInterface,uint8_t fifoThreshold)2278 int8_t ITDS_setFifoThreshold(WE_sensorInterface_t* sensorInterface, uint8_t fifoThreshold)
2279 {
2280 ITDS_fifoCtrl_t fifoCtrl;
2281
2282 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_FIFO_CTRL_REG, 1, (uint8_t *) &fifoCtrl))
2283 {
2284 return WE_FAIL;
2285 }
2286
2287 fifoCtrl.fifoThresholdLevel = fifoThreshold;
2288
2289 return ITDS_WriteReg(sensorInterface, ITDS_FIFO_CTRL_REG, 1, (uint8_t *) &fifoCtrl);
2290 }
2291
2292 /**
2293 * @brief Read the FIFO threshold
2294 * @param[in] sensorInterface Pointer to sensor interface
2295 * @param[out] fifoThreshold The returned FIFO threshold (value between 0 and 31)
2296 * @retval Error code
2297 */
ITDS_getFifoThreshold(WE_sensorInterface_t * sensorInterface,uint8_t * fifoThreshold)2298 int8_t ITDS_getFifoThreshold(WE_sensorInterface_t* sensorInterface, uint8_t *fifoThreshold)
2299 {
2300 ITDS_fifoCtrl_t fifoCtrl;
2301
2302 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_FIFO_CTRL_REG, 1, (uint8_t *) &fifoCtrl))
2303 {
2304 return WE_FAIL;
2305 }
2306
2307 *fifoThreshold = fifoCtrl.fifoThresholdLevel;
2308
2309 return WE_SUCCESS;
2310 }
2311
2312 /**
2313 * @brief Set the FIFO mode
2314 * @param[in] sensorInterface Pointer to sensor interface
2315 * @param[in] fifoMode FIFO mode
2316 * @retval Error code
2317 */
ITDS_setFifoMode(WE_sensorInterface_t * sensorInterface,ITDS_FifoMode_t fifoMode)2318 int8_t ITDS_setFifoMode(WE_sensorInterface_t* sensorInterface, ITDS_FifoMode_t fifoMode)
2319 {
2320 ITDS_fifoCtrl_t fifoCtrl;
2321
2322 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_FIFO_CTRL_REG, 1, (uint8_t *) &fifoCtrl))
2323 {
2324 return WE_FAIL;
2325 }
2326
2327 fifoCtrl.fifoMode = fifoMode;
2328
2329 return ITDS_WriteReg(sensorInterface, ITDS_FIFO_CTRL_REG, 1, (uint8_t *) &fifoCtrl);
2330 }
2331
2332 /**
2333 * @brief Read the FIFO mode
2334 * @param[in] sensorInterface Pointer to sensor interface
2335 * @param[out] fifoMode The returned FIFO mode
2336 * @retval Error code
2337 */
ITDS_getFifoMode(WE_sensorInterface_t * sensorInterface,ITDS_FifoMode_t * fifoMode)2338 int8_t ITDS_getFifoMode(WE_sensorInterface_t* sensorInterface, ITDS_FifoMode_t *fifoMode)
2339 {
2340 ITDS_fifoCtrl_t fifoCtrl;
2341
2342 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_FIFO_CTRL_REG, 1, (uint8_t *) &fifoCtrl))
2343 {
2344 return WE_FAIL;
2345 }
2346
2347 *fifoMode = (ITDS_FifoMode_t) fifoCtrl.fifoMode;
2348
2349 return WE_SUCCESS;
2350 }
2351
2352
2353 /* FIFO_SAMPLES (0x2F) */
2354
2355 /**
2356 * @brief Read the FIFO samples status
2357 * @param[in] sensorInterface Pointer to sensor interface
2358 * @param[out] fifoSamplesStatus The returned FIFO samples status
2359 * @retval Error code
2360 */
ITDS_getFifoSamplesRegister(WE_sensorInterface_t * sensorInterface,ITDS_fifoSamples_t * fifoSamplesStatus)2361 int8_t ITDS_getFifoSamplesRegister(WE_sensorInterface_t* sensorInterface, ITDS_fifoSamples_t *fifoSamplesStatus)
2362 {
2363 return ITDS_ReadReg(sensorInterface, ITDS_FIFO_SAMPLES_REG, 1, (uint8_t *) fifoSamplesStatus);
2364 }
2365
2366 /**
2367 * @brief Read the FIFO threshold state [FIFO filling is lower than threshold level /
2368 * FIFO filling is equal to or higher than the threshold level]
2369 *
2370 * @param[in] sensorInterface Pointer to sensor interface
2371 * @param[out] fifoThr The returned FIFO threshold state
2372 * @retval Error code
2373 */
ITDS_isFifoThresholdReached(WE_sensorInterface_t * sensorInterface,ITDS_state_t * fifoThr)2374 int8_t ITDS_isFifoThresholdReached(WE_sensorInterface_t* sensorInterface, ITDS_state_t *fifoThr)
2375 {
2376 ITDS_fifoSamples_t fifoSamples;
2377
2378 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_FIFO_SAMPLES_REG, 1, (uint8_t *) &fifoSamples))
2379 {
2380 return WE_FAIL;
2381 }
2382
2383 *fifoThr = (ITDS_state_t) fifoSamples.fifoThresholdState;
2384
2385 return WE_SUCCESS;
2386 }
2387
2388 /**
2389 * @brief Read the FIFO overrun state [FIFO is not completely filled /
2390 * FIFO completely filled and at least one sample has been overwritten]
2391 *
2392 * @param[in] sensorInterface Pointer to sensor interface
2393 * @param[out] fifoOverrun The returned FIFO overrun state.
2394 * @retval Error code
2395 */
ITDS_getFifoOverrunState(WE_sensorInterface_t * sensorInterface,ITDS_state_t * fifoOverrun)2396 int8_t ITDS_getFifoOverrunState(WE_sensorInterface_t* sensorInterface, ITDS_state_t *fifoOverrun)
2397 {
2398 ITDS_fifoSamples_t fifoSamples;
2399
2400 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_FIFO_SAMPLES_REG, 1, (uint8_t *) &fifoSamples))
2401 {
2402 return WE_FAIL;
2403 }
2404
2405 *fifoOverrun = (ITDS_state_t) fifoSamples.fifoOverrunState;
2406
2407 return WE_SUCCESS;
2408 }
2409
2410 /**
2411 * @brief Read the FIFO fill level
2412 * @param[in] sensorInterface Pointer to sensor interface
2413 * @param[out] fifoFill The returned FIFO fill level (0-32)
2414 * @retval Error code
2415 */
ITDS_getFifoFillLevel(WE_sensorInterface_t * sensorInterface,uint8_t * fifoFill)2416 int8_t ITDS_getFifoFillLevel(WE_sensorInterface_t* sensorInterface, uint8_t *fifoFill)
2417 {
2418 ITDS_fifoSamples_t fifoSamples;
2419
2420 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_FIFO_SAMPLES_REG, 1, (uint8_t *) &fifoSamples))
2421 {
2422 return WE_FAIL;
2423 }
2424
2425 *fifoFill = fifoSamples.fifoFillLevel;
2426
2427 return WE_SUCCESS;
2428 }
2429
2430
2431 /* TAP_X_TH (0x30) */
2432
2433 /**
2434 * @brief Enable/disable 4D orientation detection
2435 * @param[in] sensorInterface Pointer to sensor interface
2436 * @param[in] detection4D The 4D orientation detection enable state
2437 * @retval Error code
2438 */
ITDS_enable4DDetection(WE_sensorInterface_t * sensorInterface,ITDS_state_t detection4D)2439 int8_t ITDS_enable4DDetection(WE_sensorInterface_t* sensorInterface, ITDS_state_t detection4D)
2440 {
2441 ITDS_tapXThreshold_t tapXThresh;
2442
2443 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_X_TH_REG, 1, (uint8_t *) &tapXThresh))
2444 {
2445 return WE_FAIL;
2446 }
2447
2448 tapXThresh.fourDDetectionEnabled = detection4D;
2449
2450 return ITDS_WriteReg(sensorInterface, ITDS_TAP_X_TH_REG, 1, (uint8_t *) &tapXThresh);
2451 }
2452
2453 /**
2454 * @brief Check if 4D orientation detection is enabled
2455 * @param[in] sensorInterface Pointer to sensor interface
2456 * @param[out] detection4D The returned 4D orientation detection enable state.
2457 * @retval Error code
2458 */
ITDS_is4DDetectionEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * detection4D)2459 int8_t ITDS_is4DDetectionEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *detection4D)
2460 {
2461 ITDS_tapXThreshold_t tapXThresh;
2462
2463 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_X_TH_REG, 1, (uint8_t *) &tapXThresh))
2464 {
2465 return WE_FAIL;
2466 }
2467
2468 *detection4D = (ITDS_state_t) tapXThresh.fourDDetectionEnabled;
2469
2470 return WE_SUCCESS;
2471 }
2472
2473 /**
2474 * @brief Set the tap threshold for axis X
2475 * @param[in] sensorInterface Pointer to sensor interface
2476 * @param[in] tapThresholdX Tap threshold for axis X (5 bits)
2477 * @retval Error code
2478 */
ITDS_setTapThresholdX(WE_sensorInterface_t * sensorInterface,uint8_t tapThresholdX)2479 int8_t ITDS_setTapThresholdX(WE_sensorInterface_t* sensorInterface, uint8_t tapThresholdX)
2480 {
2481 ITDS_tapXThreshold_t tapXThresh;
2482
2483 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_X_TH_REG, 1, (uint8_t *) &tapXThresh))
2484 {
2485 return WE_FAIL;
2486 }
2487
2488 tapXThresh.xAxisTapThreshold = tapThresholdX;
2489
2490 return ITDS_WriteReg(sensorInterface, ITDS_TAP_X_TH_REG, 1, (uint8_t *) &tapXThresh);
2491 }
2492
2493 /**
2494 * @brief Read the tap threshold for axis X
2495 * @param[in] sensorInterface Pointer to sensor interface
2496 * @param[out] tapThresholdX The returned tap threshold for axis X
2497 * @retval Error code
2498 */
ITDS_getTapThresholdX(WE_sensorInterface_t * sensorInterface,uint8_t * tapThresholdX)2499 int8_t ITDS_getTapThresholdX(WE_sensorInterface_t* sensorInterface, uint8_t *tapThresholdX)
2500 {
2501 ITDS_tapXThreshold_t tapXThresh;
2502
2503 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_X_TH_REG, 1, (uint8_t *) &tapXThresh))
2504 {
2505 return WE_FAIL;
2506 }
2507
2508 *tapThresholdX = tapXThresh.xAxisTapThreshold;
2509
2510 return WE_SUCCESS;
2511 }
2512
2513 /**
2514 * @brief Set the 6D orientation detection threshold (degrees)
2515 * @param[in] sensorInterface Pointer to sensor interface
2516 * @param[in] threshold6D 6D orientation detection threshold
2517 * @retval Error code
2518 */
ITDS_set6DThreshold(WE_sensorInterface_t * sensorInterface,ITDS_thresholdDegree_t threshold6D)2519 int8_t ITDS_set6DThreshold(WE_sensorInterface_t* sensorInterface, ITDS_thresholdDegree_t threshold6D)
2520 {
2521 ITDS_tapXThreshold_t tapXThresh;
2522
2523 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_X_TH_REG, 1, (uint8_t *) &tapXThresh))
2524 {
2525 return WE_FAIL;
2526 }
2527
2528 tapXThresh.sixDThreshold = threshold6D;
2529
2530 return ITDS_WriteReg(sensorInterface, ITDS_TAP_X_TH_REG, 1, (uint8_t *) &tapXThresh);
2531 }
2532
2533 /**
2534 * @brief Read the 6D orientation detection threshold (degrees)
2535 * @param[in] sensorInterface Pointer to sensor interface
2536 * @param[out] threshold6D The returned 6D orientation detection threshold
2537 * @retval Error code
2538 */
ITDS_get6DThreshold(WE_sensorInterface_t * sensorInterface,ITDS_thresholdDegree_t * threshold6D)2539 int8_t ITDS_get6DThreshold(WE_sensorInterface_t* sensorInterface, ITDS_thresholdDegree_t *threshold6D)
2540 {
2541 ITDS_tapXThreshold_t tapXThresh;
2542
2543 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_X_TH_REG, 1, (uint8_t *) &tapXThresh))
2544 {
2545 return WE_FAIL;
2546 }
2547
2548 *threshold6D = (ITDS_thresholdDegree_t) tapXThresh.sixDThreshold;
2549
2550 return WE_SUCCESS;
2551 }
2552
2553
2554 /* TAP_Y_TH (0x31) */
2555
2556 /**
2557 * @brief Set the tap threshold for axis Y
2558 * @param[in] sensorInterface Pointer to sensor interface
2559 * @param[in] tapThresholdY Tap threshold for axis Y (5 bits)
2560 * @retval Error code
2561 */
ITDS_setTapThresholdY(WE_sensorInterface_t * sensorInterface,uint8_t tapThresholdY)2562 int8_t ITDS_setTapThresholdY(WE_sensorInterface_t* sensorInterface, uint8_t tapThresholdY)
2563 {
2564 ITDS_tapYThreshold_t tapYThresh;
2565
2566 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_Y_TH_REG, 1, (uint8_t *) &tapYThresh))
2567 {
2568 return WE_FAIL;
2569 }
2570
2571 tapYThresh.yAxisTapThreshold = tapThresholdY;
2572
2573 return ITDS_WriteReg(sensorInterface, ITDS_TAP_Y_TH_REG, 1, (uint8_t *) &tapYThresh);
2574 }
2575
2576 /**
2577 * @brief Read the tap threshold for axis Y
2578 * @param[in] sensorInterface Pointer to sensor interface
2579 * @param[out] tapThresholdY The returned tap threshold for axis Y.
2580 * @retval Error code
2581 */
ITDS_getTapThresholdY(WE_sensorInterface_t * sensorInterface,uint8_t * tapThresholdY)2582 int8_t ITDS_getTapThresholdY(WE_sensorInterface_t* sensorInterface, uint8_t *tapThresholdY)
2583 {
2584 ITDS_tapYThreshold_t tapYThresh;
2585
2586 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_Y_TH_REG, 1, (uint8_t *) &tapYThresh))
2587 {
2588 return WE_FAIL;
2589 }
2590
2591 *tapThresholdY = tapYThresh.yAxisTapThreshold;
2592 return WE_SUCCESS;
2593 }
2594
2595 /**
2596 * @brief Set the axis tap detection priority
2597 * @param[in] sensorInterface Pointer to sensor interface
2598 * @param[in] priority Axis tap detection priority
2599 * @retval Error code
2600 */
ITDS_setTapAxisPriority(WE_sensorInterface_t * sensorInterface,ITDS_tapAxisPriority_t priority)2601 int8_t ITDS_setTapAxisPriority(WE_sensorInterface_t* sensorInterface, ITDS_tapAxisPriority_t priority)
2602 {
2603 ITDS_tapYThreshold_t tapYThresh;
2604
2605 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_Y_TH_REG, 1, (uint8_t *) &tapYThresh))
2606 {
2607 return WE_FAIL;
2608 }
2609
2610 tapYThresh.tapAxisPriority = priority;
2611
2612 return ITDS_WriteReg(sensorInterface, ITDS_TAP_Y_TH_REG, 1, (uint8_t *) &tapYThresh);
2613 }
2614
2615 /**
2616 * @brief Read the axis tap detection priority
2617 * @param[in] sensorInterface Pointer to sensor interface
2618 * @param[out] priority The returned axis tap detection priority
2619 * @retval Error code
2620 */
ITDS_getTapAxisPriority(WE_sensorInterface_t * sensorInterface,ITDS_tapAxisPriority_t * priority)2621 int8_t ITDS_getTapAxisPriority(WE_sensorInterface_t* sensorInterface, ITDS_tapAxisPriority_t *priority)
2622 {
2623 ITDS_tapYThreshold_t tapYThresh;
2624
2625 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_Y_TH_REG, 1, (uint8_t *) &tapYThresh))
2626 {
2627 return WE_FAIL;
2628 }
2629
2630 *priority = (ITDS_tapAxisPriority_t) tapYThresh.tapAxisPriority;
2631
2632 return WE_SUCCESS;
2633 }
2634
2635
2636 /* TAP_Z_TH (0x32) */
2637
2638 /**
2639 * @brief Set the tap threshold for axis Z
2640 * @param[in] sensorInterface Pointer to sensor interface
2641 * @param[in] tapThresholdZ Tap threshold for axis Z (5 bits)
2642 * @retval Error code
2643 */
ITDS_setTapThresholdZ(WE_sensorInterface_t * sensorInterface,uint8_t tapThresholdZ)2644 int8_t ITDS_setTapThresholdZ(WE_sensorInterface_t* sensorInterface, uint8_t tapThresholdZ)
2645 {
2646 ITDS_tapZThreshold_t tapZThresh;
2647
2648 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_Z_TH_REG, 1, (uint8_t *) &tapZThresh))
2649 {
2650 return WE_FAIL;
2651 }
2652
2653 tapZThresh.zAxisTapThreshold = tapThresholdZ;
2654
2655 return ITDS_WriteReg(sensorInterface, ITDS_TAP_Z_TH_REG, 1, (uint8_t *) &tapZThresh);
2656 }
2657
2658 /**
2659 * @brief Read the tap threshold for axis Z
2660 * @param[in] sensorInterface Pointer to sensor interface
2661 * @param[out] tapThresholdZ The returned tap threshold for axis Z.
2662 * @retval Error code
2663 */
ITDS_getTapThresholdZ(WE_sensorInterface_t * sensorInterface,uint8_t * tapThresholdZ)2664 int8_t ITDS_getTapThresholdZ(WE_sensorInterface_t* sensorInterface, uint8_t *tapThresholdZ)
2665 {
2666 ITDS_tapZThreshold_t tapZThresh;
2667
2668 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_Z_TH_REG, 1, (uint8_t *) &tapZThresh))
2669 {
2670 return WE_FAIL;
2671 }
2672
2673 *tapThresholdZ = tapZThresh.zAxisTapThreshold;
2674
2675 return WE_SUCCESS;
2676 }
2677
2678 /**
2679 * @brief Enable/disable tap recognition in X direction
2680 * @param[in] sensorInterface Pointer to sensor interface
2681 * @param[in] tapX Tap X direction state
2682 * @retval Error code
2683 */
ITDS_enableTapX(WE_sensorInterface_t * sensorInterface,ITDS_state_t tapX)2684 int8_t ITDS_enableTapX(WE_sensorInterface_t* sensorInterface, ITDS_state_t tapX)
2685 {
2686 ITDS_tapZThreshold_t tapZThresh;
2687
2688 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_Z_TH_REG, 1, (uint8_t *) &tapZThresh))
2689 {
2690 return WE_FAIL;
2691 }
2692
2693 tapZThresh.enTapX = tapX;
2694
2695 return ITDS_WriteReg(sensorInterface, ITDS_TAP_Z_TH_REG, 1, (uint8_t *) &tapZThresh);
2696 }
2697
2698 /**
2699 * @brief Check if detection of tap events in X direction is enabled
2700 * @param[in] sensorInterface Pointer to sensor interface
2701 * @param[out] tapX The returned tap X direction state
2702 * @retval Error code
2703 */
ITDS_isTapXEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * tapX)2704 int8_t ITDS_isTapXEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *tapX)
2705 {
2706 ITDS_tapZThreshold_t tapZThresh;
2707
2708 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_Z_TH_REG, 1, (uint8_t *) &tapZThresh))
2709 {
2710 return WE_FAIL;
2711 }
2712
2713 *tapX = (ITDS_state_t) tapZThresh.enTapX;
2714
2715 return WE_SUCCESS;
2716 }
2717
2718 /**
2719 * @brief Enable/disable tap recognition in Y direction
2720 * @param[in] sensorInterface Pointer to sensor interface
2721 * @param[in] tapY Tap Y direction state
2722 * @retval Error code
2723 */
ITDS_enableTapY(WE_sensorInterface_t * sensorInterface,ITDS_state_t tapY)2724 int8_t ITDS_enableTapY(WE_sensorInterface_t* sensorInterface, ITDS_state_t tapY)
2725 {
2726 ITDS_tapZThreshold_t tapZThresh;
2727
2728 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_Z_TH_REG, 1, (uint8_t *) &tapZThresh))
2729 {
2730 return WE_FAIL;
2731 }
2732
2733 tapZThresh.enTapY = tapY;
2734
2735 return ITDS_WriteReg(sensorInterface, ITDS_TAP_Z_TH_REG, 1, (uint8_t *) &tapZThresh);
2736 }
2737
2738 /**
2739 * @brief Check if detection of tap events in Y direction is enabled
2740 * @param[in] sensorInterface Pointer to sensor interface
2741 * @param[out] tapY The returned tap Y direction state
2742 * @retval Error code
2743 */
ITDS_isTapYEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * tapY)2744 int8_t ITDS_isTapYEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *tapY)
2745 {
2746 ITDS_tapZThreshold_t tapZThresh;
2747
2748 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_Z_TH_REG, 1, (uint8_t *) &tapZThresh))
2749 {
2750 return WE_FAIL;
2751 }
2752
2753 *tapY = (ITDS_state_t) tapZThresh.enTapY;
2754
2755 return WE_SUCCESS;
2756 }
2757
2758 /**
2759 * @brief Enable/disable tap recognition in Z direction
2760 * @param[in] sensorInterface Pointer to sensor interface
2761 * @param[in] tapZ Tap Z direction state
2762 * @retval Error code
2763 */
ITDS_enableTapZ(WE_sensorInterface_t * sensorInterface,ITDS_state_t tapZ)2764 int8_t ITDS_enableTapZ(WE_sensorInterface_t* sensorInterface, ITDS_state_t tapZ)
2765 {
2766 ITDS_tapZThreshold_t tapZThresh;
2767
2768 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_Z_TH_REG, 1, (uint8_t *) &tapZThresh))
2769 {
2770 return WE_FAIL;
2771 }
2772
2773 tapZThresh.enTapZ = tapZ;
2774
2775 return ITDS_WriteReg(sensorInterface, ITDS_TAP_Z_TH_REG, 1, (uint8_t *) &tapZThresh);
2776 }
2777
2778 /**
2779 * @brief Check if detection of tap events in Z direction is enabled
2780 * @param[in] sensorInterface Pointer to sensor interface
2781 * @param[out] tapZ The returned tap Z direction state
2782 * @retval Error code
2783 */
ITDS_isTapZEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * tapZ)2784 int8_t ITDS_isTapZEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *tapZ)
2785 {
2786 ITDS_tapZThreshold_t tapZThresh;
2787
2788 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_Z_TH_REG, 1, (uint8_t *) &tapZThresh))
2789 {
2790 return WE_FAIL;
2791 }
2792
2793 *tapZ = (ITDS_state_t) tapZThresh.enTapZ;
2794
2795 return WE_SUCCESS;
2796 }
2797
2798
2799 /* INT_DUR (0x33) */
2800
2801 /**
2802 * @brief Set the maximum duration time gap for double-tap recognition (LATENCY)
2803 * @param[in] sensorInterface Pointer to sensor interface
2804 * @param[in] latencyTime Latency value (4 bits)
2805 * @retval Error code
2806 */
ITDS_setTapLatencyTime(WE_sensorInterface_t * sensorInterface,uint8_t latencyTime)2807 int8_t ITDS_setTapLatencyTime(WE_sensorInterface_t* sensorInterface, uint8_t latencyTime)
2808 {
2809 ITDS_intDuration_t intDuration;
2810
2811 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_INT_DUR_REG, 1, (uint8_t *) &intDuration))
2812 {
2813 return WE_FAIL;
2814 }
2815
2816 intDuration.latency = latencyTime;
2817
2818 return ITDS_WriteReg(sensorInterface, ITDS_INT_DUR_REG, 1, (uint8_t *) &intDuration);
2819 }
2820
2821 /**
2822 * @brief Read the maximum duration time gap for double-tap recognition (LATENCY)
2823 * @param[in] sensorInterface Pointer to sensor interface
2824 * @param[out] latencyTime The returned latency time
2825 * @retval Error code
2826 */
ITDS_getTapLatencyTime(WE_sensorInterface_t * sensorInterface,uint8_t * latencyTime)2827 int8_t ITDS_getTapLatencyTime(WE_sensorInterface_t* sensorInterface, uint8_t *latencyTime)
2828 {
2829 ITDS_intDuration_t intDuration;
2830
2831 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_INT_DUR_REG, 1, (uint8_t *) &intDuration))
2832 {
2833 return WE_FAIL;
2834 }
2835
2836 *latencyTime = intDuration.latency;
2837
2838 return WE_SUCCESS;
2839 }
2840
2841 /**
2842 * @brief Set the expected quiet time after a tap detection (QUIET)
2843 * @param[in] sensorInterface Pointer to sensor interface
2844 * @param[in] quietTime Quiet time value (2 bits)
2845 * @retval Error code
2846 */
ITDS_setTapQuietTime(WE_sensorInterface_t * sensorInterface,uint8_t quietTime)2847 int8_t ITDS_setTapQuietTime(WE_sensorInterface_t* sensorInterface, uint8_t quietTime)
2848 {
2849 ITDS_intDuration_t intDuration;
2850
2851 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_INT_DUR_REG, 1, (uint8_t *) &intDuration))
2852 {
2853 return WE_FAIL;
2854 }
2855
2856 intDuration.quiet = quietTime;
2857
2858 return ITDS_WriteReg(sensorInterface, ITDS_INT_DUR_REG, 1, (uint8_t *) &intDuration);
2859 }
2860
2861 /**
2862 * @brief Read the expected quiet time after a tap detection (QUIET)
2863 * @param[in] sensorInterface Pointer to sensor interface
2864 * @param[out] quietTime The returned quiet time
2865 * @retval Error code
2866 */
ITDS_getTapQuietTime(WE_sensorInterface_t * sensorInterface,uint8_t * quietTime)2867 int8_t ITDS_getTapQuietTime(WE_sensorInterface_t* sensorInterface, uint8_t *quietTime)
2868 {
2869
2870 ITDS_intDuration_t intDuration;
2871
2872 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_INT_DUR_REG, 1, (uint8_t *) &intDuration))
2873 {
2874 return WE_FAIL;
2875 }
2876
2877 *quietTime = intDuration.quiet;
2878
2879 return WE_SUCCESS;
2880 }
2881
2882 /**
2883 * @brief Set the maximum duration of over-threshold events (SHOCK)
2884 * @param[in] sensorInterface Pointer to sensor interface
2885 * @param[in] shockTime Shock time value (2 bits)
2886 * @retval Error code
2887 */
ITDS_setTapShockTime(WE_sensorInterface_t * sensorInterface,uint8_t shockTime)2888 int8_t ITDS_setTapShockTime(WE_sensorInterface_t* sensorInterface, uint8_t shockTime)
2889 {
2890 ITDS_intDuration_t intDuration;
2891
2892 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_INT_DUR_REG, 1, (uint8_t *) &intDuration))
2893 {
2894 return WE_FAIL;
2895 }
2896
2897 intDuration.shock = shockTime;
2898
2899 return ITDS_WriteReg(sensorInterface, ITDS_INT_DUR_REG, 1, (uint8_t *) &intDuration);
2900 }
2901
2902 /**
2903 * @brief Read the maximum duration of over-threshold events (SHOCK)
2904 * @param[in] sensorInterface Pointer to sensor interface
2905 * @param[out] shockTime The returned shock time.
2906 * @retval Error code
2907 */
ITDS_getTapShockTime(WE_sensorInterface_t * sensorInterface,uint8_t * shockTime)2908 int8_t ITDS_getTapShockTime(WE_sensorInterface_t* sensorInterface, uint8_t *shockTime)
2909 {
2910 ITDS_intDuration_t intDuration;
2911
2912 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_INT_DUR_REG, 1, (uint8_t *) &intDuration))
2913 {
2914 return WE_FAIL;
2915 }
2916
2917 *shockTime = intDuration.shock;
2918
2919 return WE_SUCCESS;
2920 }
2921
2922
2923 /* WAKE_UP_TH */
2924
2925 /**
2926 * @brief Enable/disable the single and double-tap event OR only single-tap event
2927 * @param[in] sensorInterface Pointer to sensor interface
2928 * @param[in] doubleTap Tap event state [0: only single, 1: single and double-tap]
2929 * @retval Error code
2930 */
ITDS_enableDoubleTapEvent(WE_sensorInterface_t * sensorInterface,ITDS_state_t doubleTap)2931 int8_t ITDS_enableDoubleTapEvent(WE_sensorInterface_t* sensorInterface, ITDS_state_t doubleTap)
2932 {
2933 ITDS_wakeUpThreshold_t wakeUpThreshReg;
2934
2935 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_TH_REG, 1, (uint8_t *) &wakeUpThreshReg))
2936 {
2937 return WE_FAIL;
2938 }
2939
2940 wakeUpThreshReg.enDoubleTapEvent = doubleTap;
2941
2942 return ITDS_WriteReg(sensorInterface, ITDS_WAKE_UP_TH_REG, 1, (uint8_t *) &wakeUpThreshReg);
2943 }
2944
2945 /**
2946 * @brief Check if double-tap events are enabled
2947 * @param[in] sensorInterface Pointer to sensor interface
2948 * @param[out] doubleTap The returned tap event state [0: only single, 1: single and double-tap]
2949 * @retval Error code
2950 */
ITDS_isDoubleTapEventEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * doubleTap)2951 int8_t ITDS_isDoubleTapEventEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *doubleTap)
2952 {
2953 ITDS_wakeUpThreshold_t wakeUpThreshReg;
2954
2955 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_TH_REG, 1, (uint8_t *) &wakeUpThreshReg))
2956 {
2957 return WE_FAIL;
2958 }
2959
2960 *doubleTap = (ITDS_state_t) wakeUpThreshReg.enDoubleTapEvent;
2961
2962 return WE_SUCCESS;
2963 }
2964
2965 /**
2966 * @brief Enable/disable inactivity (sleep) detection
2967 * @param[in] sensorInterface Pointer to sensor interface
2968 * @param[in] inactivity Sleep detection enable state
2969 * @retval Error code
2970 */
ITDS_enableInactivityDetection(WE_sensorInterface_t * sensorInterface,ITDS_state_t inactivity)2971 int8_t ITDS_enableInactivityDetection(WE_sensorInterface_t* sensorInterface, ITDS_state_t inactivity)
2972 {
2973 ITDS_wakeUpThreshold_t wakeUpThreshReg;
2974
2975 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_TH_REG, 1, (uint8_t *) &wakeUpThreshReg))
2976 {
2977 return WE_FAIL;
2978 }
2979
2980 wakeUpThreshReg.enInactivityEvent = inactivity;
2981
2982 return ITDS_WriteReg(sensorInterface, ITDS_WAKE_UP_TH_REG, 1, (uint8_t *) &wakeUpThreshReg);
2983 }
2984
2985 /**
2986 * @brief Check if inactivity (sleep) detection is enabled
2987 * @param[in] sensorInterface Pointer to sensor interface
2988 * @param[out] inactivity The returned inactivity (sleep) detection enable state.
2989 * @retval Error code
2990 */
ITDS_isInactivityDetectionEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * inactivity)2991 int8_t ITDS_isInactivityDetectionEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *inactivity)
2992 {
2993 ITDS_wakeUpThreshold_t wakeUpThreshReg;
2994
2995 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_TH_REG, 1, (uint8_t *) &wakeUpThreshReg))
2996 {
2997 return WE_FAIL;
2998 }
2999
3000 *inactivity = (ITDS_state_t) wakeUpThreshReg.enInactivityEvent;
3001
3002 return WE_SUCCESS;
3003 }
3004
3005 /**
3006 * @brief Set wake-up threshold
3007 * @param[in] sensorInterface Pointer to sensor interface
3008 * @param[in] wakeUpThresh Wake-up threshold (six bits)
3009 * @retval Error code
3010 */
ITDS_setWakeUpThreshold(WE_sensorInterface_t * sensorInterface,uint8_t wakeUpThresh)3011 int8_t ITDS_setWakeUpThreshold(WE_sensorInterface_t* sensorInterface, uint8_t wakeUpThresh)
3012 {
3013 ITDS_wakeUpThreshold_t wakeUpThreshReg;
3014
3015 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_TH_REG, 1, (uint8_t *) &wakeUpThreshReg))
3016 {
3017 return WE_FAIL;
3018 }
3019
3020 wakeUpThreshReg.wakeUpThreshold = wakeUpThresh;
3021
3022 return ITDS_WriteReg(sensorInterface, ITDS_WAKE_UP_TH_REG, 1, (uint8_t *) &wakeUpThreshReg);
3023 }
3024
3025 /**
3026 * @brief Read the wake-up threshold
3027 * @param[in] sensorInterface Pointer to sensor interface
3028 * @param[out] wakeUpThresh The returned wake-up threshold.
3029 * @retval Error code
3030 */
ITDS_getWakeUpThreshold(WE_sensorInterface_t * sensorInterface,uint8_t * wakeUpThresh)3031 int8_t ITDS_getWakeUpThreshold(WE_sensorInterface_t* sensorInterface, uint8_t *wakeUpThresh)
3032 {
3033 ITDS_wakeUpThreshold_t wakeUpThreshReg;
3034
3035 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_TH_REG, 1, (uint8_t *) &wakeUpThreshReg))
3036 {
3037 return WE_FAIL;
3038 }
3039
3040 *wakeUpThresh = wakeUpThreshReg.wakeUpThreshold;
3041
3042 return WE_SUCCESS;
3043 }
3044
3045
3046 /* WAKE_UP_DUR */
3047
3048 /**
3049 * @brief Set free-fall duration MSB
3050 * @param[in] sensorInterface Pointer to sensor interface
3051 * @param[in] freeFallDurationMsb Free-fall duration MSB
3052 * @retval Error code
3053 */
ITDS_setFreeFallDurationMSB(WE_sensorInterface_t * sensorInterface,uint8_t freeFallDurationMsb)3054 int8_t ITDS_setFreeFallDurationMSB(WE_sensorInterface_t* sensorInterface, uint8_t freeFallDurationMsb)
3055 {
3056 ITDS_wakeUpDuration_t wakeUpDuration;
3057
3058 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_DUR_REG, 1, (uint8_t *) &wakeUpDuration))
3059 {
3060 return WE_FAIL;
3061 }
3062
3063 wakeUpDuration.freeFallDurationMSB = freeFallDurationMsb;
3064
3065 return ITDS_WriteReg(sensorInterface, ITDS_WAKE_UP_DUR_REG, 1, (uint8_t *) &wakeUpDuration);
3066 }
3067
3068 /**
3069 * @brief Read the free-fall duration MSB
3070 * @param[in] sensorInterface Pointer to sensor interface
3071 * @param[out] freeFallDurationMsb The returned free-fall duration MSB
3072 * @retval Error code
3073 */
ITDS_getFreeFallDurationMSB(WE_sensorInterface_t * sensorInterface,uint8_t * freeFallDurationMsb)3074 int8_t ITDS_getFreeFallDurationMSB(WE_sensorInterface_t* sensorInterface, uint8_t *freeFallDurationMsb)
3075 {
3076 ITDS_wakeUpDuration_t wakeUpDuration;
3077
3078 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_DUR_REG, 1, (uint8_t *) &wakeUpDuration))
3079 {
3080 return WE_FAIL;
3081 }
3082
3083 *freeFallDurationMsb = wakeUpDuration.freeFallDurationMSB;
3084 return WE_SUCCESS;
3085 }
3086
3087 /**
3088 * @brief Enable/disable stationary detection
3089 * @param[in] sensorInterface Pointer to sensor interface
3090 * @param[in] stationary Stationary detection enable state
3091 * @retval Error code
3092 */
ITDS_enableStationaryDetection(WE_sensorInterface_t * sensorInterface,ITDS_state_t stationary)3093 int8_t ITDS_enableStationaryDetection(WE_sensorInterface_t* sensorInterface, ITDS_state_t stationary)
3094 {
3095 ITDS_wakeUpDuration_t wakeUpDuration;
3096
3097 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_DUR_REG, 1, (uint8_t *) &wakeUpDuration))
3098 {
3099 return WE_FAIL;
3100 }
3101
3102 wakeUpDuration.enStationary = stationary;
3103
3104 return ITDS_WriteReg(sensorInterface, ITDS_WAKE_UP_DUR_REG, 1, (uint8_t *) &wakeUpDuration);
3105 }
3106
3107 /**
3108 * @brief Check if stationary detection is enabled
3109 * @param[in] sensorInterface Pointer to sensor interface
3110 * @param[out] stationary The returned stationary detection enable state
3111 * @retval Error code
3112 */
ITDS_isStationaryDetectionEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * stationary)3113 int8_t ITDS_isStationaryDetectionEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *stationary)
3114 {
3115 ITDS_wakeUpDuration_t wakeUpDuration;
3116
3117 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_DUR_REG, 1, (uint8_t *) &wakeUpDuration))
3118 {
3119 return WE_FAIL;
3120 }
3121
3122 *stationary = (ITDS_state_t) wakeUpDuration.enStationary;
3123
3124 return WE_SUCCESS;
3125 }
3126
3127 /**
3128 * @brief Set wake-up duration
3129 * @param[in] sensorInterface Pointer to sensor interface
3130 * @param[in] duration Wake-up duration (two bits)
3131 * @retval Error code
3132 */
ITDS_setWakeUpDuration(WE_sensorInterface_t * sensorInterface,uint8_t duration)3133 int8_t ITDS_setWakeUpDuration(WE_sensorInterface_t* sensorInterface, uint8_t duration)
3134 {
3135 ITDS_wakeUpDuration_t wakeUpDuration;
3136
3137 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_DUR_REG, 1, (uint8_t *) &wakeUpDuration))
3138 {
3139 return WE_FAIL;
3140 }
3141
3142 wakeUpDuration.wakeUpDuration = duration;
3143
3144 return ITDS_WriteReg(sensorInterface, ITDS_WAKE_UP_DUR_REG, 1, (uint8_t *) &wakeUpDuration);
3145 }
3146
3147 /**
3148 * @brief Read the wake-up duration
3149 * @param[in] sensorInterface Pointer to sensor interface
3150 * @param[out] duration The returned wake-up duration (two bits)
3151 * @retval Error code
3152 */
ITDS_getWakeUpDuration(WE_sensorInterface_t * sensorInterface,uint8_t * duration)3153 int8_t ITDS_getWakeUpDuration(WE_sensorInterface_t* sensorInterface, uint8_t *duration)
3154 {
3155 ITDS_wakeUpDuration_t wakeUpDuration;
3156
3157 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_DUR_REG, 1, (uint8_t *) &wakeUpDuration))
3158 {
3159 return WE_FAIL;
3160 }
3161
3162 *duration = wakeUpDuration.wakeUpDuration;
3163
3164 return WE_SUCCESS;
3165 }
3166
3167 /**
3168 * @brief Set the sleep mode duration
3169 * @param[in] sensorInterface Pointer to sensor interface
3170 * @param[in] duration Sleep mode duration (4 bits)
3171 * @retval Error code
3172 */
ITDS_setSleepDuration(WE_sensorInterface_t * sensorInterface,uint8_t duration)3173 int8_t ITDS_setSleepDuration(WE_sensorInterface_t* sensorInterface, uint8_t duration)
3174 {
3175 ITDS_wakeUpDuration_t wakeUpDuration;
3176
3177 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_DUR_REG, 1, (uint8_t *) &wakeUpDuration))
3178 {
3179 return WE_FAIL;
3180 }
3181
3182 wakeUpDuration.sleepDuration = duration;
3183
3184 return ITDS_WriteReg(sensorInterface, ITDS_WAKE_UP_DUR_REG, 1, (uint8_t *) &wakeUpDuration);
3185 }
3186
3187 /**
3188 * @brief Read the sleep mode duration
3189 * @param[in] sensorInterface Pointer to sensor interface
3190 * @param[out] duration The returned sleep mode duration
3191 * @retval Error code
3192 */
ITDS_getSleepDuration(WE_sensorInterface_t * sensorInterface,uint8_t * duration)3193 int8_t ITDS_getSleepDuration(WE_sensorInterface_t* sensorInterface, uint8_t *duration)
3194 {
3195 ITDS_wakeUpDuration_t wakeUpDuration;
3196
3197 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_DUR_REG, 1, (uint8_t *) &wakeUpDuration))
3198 {
3199 return WE_FAIL;
3200 }
3201
3202 *duration = wakeUpDuration.sleepDuration;
3203
3204 return WE_SUCCESS;
3205 }
3206
3207
3208 /* FREE_FALL */
3209
3210 /**
3211 * @brief Set the free-fall duration (both LSB and MSB).
3212 * @param[in] sensorInterface Pointer to sensor interface
3213 * @param[in] freeFallDuration Free-fall duration (6 bits)
3214 * @retval Error code
3215 */
ITDS_setFreeFallDuration(WE_sensorInterface_t * sensorInterface,uint8_t freeFallDuration)3216 int8_t ITDS_setFreeFallDuration(WE_sensorInterface_t* sensorInterface, uint8_t freeFallDuration)
3217 {
3218 /* Set first 5 bits as LSB, 6th bit as MSB */
3219 if (WE_FAIL == ITDS_setFreeFallDurationLSB(sensorInterface, freeFallDuration & 0x1F))
3220 {
3221 return WE_FAIL;
3222 }
3223 return ITDS_setFreeFallDurationMSB(sensorInterface, (freeFallDuration >> 5) & 0x1);
3224 }
3225
3226 /**
3227 * @brief Read the free-fall duration (both LSB and MSB).
3228 * @param[in] sensorInterface Pointer to sensor interface
3229 * @param[out] freeFallDuration The returned free-fall duration (6 bits)
3230 * @retval Error code
3231 */
ITDS_getFreeFallDuration(WE_sensorInterface_t * sensorInterface,uint8_t * freeFallDuration)3232 int8_t ITDS_getFreeFallDuration(WE_sensorInterface_t* sensorInterface, uint8_t *freeFallDuration)
3233 {
3234 uint8_t lsb;
3235 uint8_t msb;
3236
3237 if (WE_FAIL == ITDS_getFreeFallDurationLSB(sensorInterface, &lsb))
3238 {
3239 return WE_FAIL;
3240 }
3241 if (WE_FAIL == ITDS_getFreeFallDurationMSB(sensorInterface, &msb))
3242 {
3243 return WE_FAIL;
3244 }
3245
3246 *freeFallDuration = (lsb & 0x1F) | ((msb & 0x1) << 5);
3247
3248 return WE_SUCCESS;
3249 }
3250
3251 /**
3252 * @brief Set free-fall duration LSB
3253 * @param[in] sensorInterface Pointer to sensor interface
3254 * @param[in] freeFallDurationLsb Free-fall duration LSB (5 bits)
3255 * @retval Error code
3256 */
ITDS_setFreeFallDurationLSB(WE_sensorInterface_t * sensorInterface,uint8_t freeFallDurationLsb)3257 int8_t ITDS_setFreeFallDurationLSB(WE_sensorInterface_t* sensorInterface, uint8_t freeFallDurationLsb)
3258 {
3259 ITDS_freeFall_t freeFall;
3260
3261 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_FREE_FALL_REG, 1, (uint8_t *) &freeFall))
3262 {
3263 return WE_FAIL;
3264 }
3265
3266 freeFall.freeFallDurationLSB = freeFallDurationLsb;
3267
3268 return ITDS_WriteReg(sensorInterface, ITDS_FREE_FALL_REG, 1, (uint8_t *) &freeFall);
3269 }
3270
3271 /**
3272 * @brief Read the free-fall duration LSB
3273 * @param[in] sensorInterface Pointer to sensor interface
3274 * @param[out] freeFallDurationLsb The returned free-fall duration LSB (5 bits)
3275 * @retval Error code
3276 */
ITDS_getFreeFallDurationLSB(WE_sensorInterface_t * sensorInterface,uint8_t * freeFallDurationLsb)3277 int8_t ITDS_getFreeFallDurationLSB(WE_sensorInterface_t* sensorInterface, uint8_t *freeFallDurationLsb)
3278 {
3279 ITDS_freeFall_t freeFall;
3280
3281 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_FREE_FALL_REG, 1, (uint8_t *) &freeFall))
3282 {
3283 return WE_FAIL;
3284 }
3285
3286 *freeFallDurationLsb = freeFall.freeFallDurationLSB;
3287 return WE_SUCCESS;
3288 }
3289
3290 /**
3291 * @brief Set free-fall threshold
3292 * @param[in] sensorInterface Pointer to sensor interface
3293 * @param[in] threshold Encoded free-fall threshold value (3 bits)
3294 * @retval Error code
3295 */
ITDS_setFreeFallThreshold(WE_sensorInterface_t * sensorInterface,ITDS_FreeFallThreshold_t threshold)3296 int8_t ITDS_setFreeFallThreshold(WE_sensorInterface_t* sensorInterface, ITDS_FreeFallThreshold_t threshold)
3297 {
3298 ITDS_freeFall_t freeFall;
3299
3300 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_FREE_FALL_REG, 1, (uint8_t *) &freeFall))
3301 {
3302 return WE_FAIL;
3303 }
3304
3305 freeFall.freeFallThreshold = threshold;
3306
3307 return ITDS_WriteReg(sensorInterface, ITDS_FREE_FALL_REG, 1, (uint8_t *) &freeFall);
3308 }
3309
3310 /**
3311 * @brief Read the free-fall threshold
3312 * @param[in] sensorInterface Pointer to sensor interface
3313 * @param[out] threshold The returned encoded free-fall threshold value (3 bits)
3314 * @retval Error code
3315 */
ITDS_getFreeFallThreshold(WE_sensorInterface_t * sensorInterface,ITDS_FreeFallThreshold_t * threshold)3316 int8_t ITDS_getFreeFallThreshold(WE_sensorInterface_t* sensorInterface, ITDS_FreeFallThreshold_t *threshold)
3317 {
3318 ITDS_freeFall_t freeFall;
3319
3320 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_FREE_FALL_REG, 1, (uint8_t *) &freeFall))
3321 {
3322 return WE_FAIL;
3323 }
3324
3325 *threshold = (ITDS_FreeFallThreshold_t) freeFall.freeFallThreshold;
3326 return WE_SUCCESS;
3327 }
3328
3329
3330 /* STATUS_DETECT */
3331 /* Note: Most of the status bits are already covered by the STATUS_REG register. */
3332
3333 /**
3334 * @brief Read the status detect register state
3335 * @param[in] sensorInterface Pointer to sensor interface
3336 * @param[out] statusDetect The returned status detect register state
3337 * @retval Error code
3338 */
ITDS_getStatusDetectRegister(WE_sensorInterface_t * sensorInterface,ITDS_statusDetect_t * statusDetect)3339 int8_t ITDS_getStatusDetectRegister(WE_sensorInterface_t* sensorInterface, ITDS_statusDetect_t *statusDetect)
3340 {
3341 return ITDS_ReadReg(sensorInterface, ITDS_STATUS_DETECT_REG, 1, (uint8_t *) statusDetect);
3342 }
3343
3344 /**
3345 * @brief Check if new temperature samples are available.
3346 * @param[in] sensorInterface Pointer to sensor interface
3347 * @param[out] dataReady The returned data-ready state
3348 * @retval Error code
3349 */
ITDS_isTemperatureDataReady(WE_sensorInterface_t * sensorInterface,ITDS_state_t * dataReady)3350 int8_t ITDS_isTemperatureDataReady(WE_sensorInterface_t* sensorInterface, ITDS_state_t *dataReady)
3351 {
3352 ITDS_statusDetect_t statusDetect;
3353
3354 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_STATUS_DETECT_REG, 1, (uint8_t *) &statusDetect))
3355 {
3356 return WE_FAIL;
3357 }
3358
3359 *dataReady = (ITDS_state_t) statusDetect.temperatureDataReady;
3360 return WE_SUCCESS;
3361 }
3362
3363
3364 /* WAKE_UP_EVENT */
3365
3366 /**
3367 * @brief Read the overall wake-up event status
3368 * @param[in] sensorInterface Pointer to sensor interface
3369 * @param[out] status The returned wake-up event status
3370 * @retval Error code
3371 */
ITDS_getWakeUpEventRegister(WE_sensorInterface_t * sensorInterface,ITDS_wakeUpEvent_t * status)3372 int8_t ITDS_getWakeUpEventRegister(WE_sensorInterface_t* sensorInterface, ITDS_wakeUpEvent_t *status)
3373 {
3374 return ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_EVENT_REG, 1, (uint8_t *) status);
3375 }
3376
3377 /**
3378 * @brief Read the wake-up event detection status on axis X
3379 * @param[in] sensorInterface Pointer to sensor interface
3380 * @param[out] wakeUpX The returned wake-up event detection status on axis X.
3381 * @retval Error code
3382 */
ITDS_isWakeUpXEvent(WE_sensorInterface_t * sensorInterface,ITDS_state_t * wakeUpX)3383 int8_t ITDS_isWakeUpXEvent(WE_sensorInterface_t* sensorInterface, ITDS_state_t *wakeUpX)
3384 {
3385 ITDS_wakeUpEvent_t wakeUpEvent;
3386
3387 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_EVENT_REG, 1, (uint8_t *) &wakeUpEvent))
3388 {
3389 return WE_FAIL;
3390 }
3391
3392 *wakeUpX = (ITDS_state_t) wakeUpEvent.wakeUpX;
3393
3394 return WE_SUCCESS;
3395 }
3396
3397 /**
3398 * @brief Read the wake-up event detection status on axis Y
3399 * @param[in] sensorInterface Pointer to sensor interface
3400 * @param[out] wakeUpY The returned wake-up event detection status on axis Y.
3401 * @retval Error code
3402 */
ITDS_isWakeUpYEvent(WE_sensorInterface_t * sensorInterface,ITDS_state_t * wakeUpY)3403 int8_t ITDS_isWakeUpYEvent(WE_sensorInterface_t* sensorInterface, ITDS_state_t *wakeUpY)
3404 {
3405 ITDS_wakeUpEvent_t wakeUpEvent;
3406
3407 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_EVENT_REG, 1, (uint8_t *) &wakeUpEvent))
3408 {
3409 return WE_FAIL;
3410 }
3411
3412 *wakeUpY = (ITDS_state_t) wakeUpEvent.wakeUpY;
3413
3414 return WE_SUCCESS;
3415 }
3416
3417 /**
3418 * @brief Read the wake-up event detection status on axis Z
3419 * @param[in] sensorInterface Pointer to sensor interface
3420 * @param[out] wakeUpZ The returned wake-up event detection status on axis Z.
3421 * @retval Error code
3422 */
ITDS_isWakeUpZEvent(WE_sensorInterface_t * sensorInterface,ITDS_state_t * wakeUpZ)3423 int8_t ITDS_isWakeUpZEvent(WE_sensorInterface_t* sensorInterface, ITDS_state_t *wakeUpZ)
3424 {
3425 ITDS_wakeUpEvent_t wakeUpEvent;
3426
3427 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_EVENT_REG, 1, (uint8_t *) &wakeUpEvent))
3428 {
3429 return WE_FAIL;
3430 }
3431
3432 *wakeUpZ = (ITDS_state_t) wakeUpEvent.wakeUpZ;
3433
3434 return WE_SUCCESS;
3435 }
3436
3437 /**
3438 * @brief Read the wake-up event detection status (wake-up event on any axis)
3439 * @param[in] sensorInterface Pointer to sensor interface
3440 * @param[out] wakeUpState The returned wake-up event detection state.
3441 * @retval Error code
3442 */
ITDS_isWakeUpEvent(WE_sensorInterface_t * sensorInterface,ITDS_state_t * wakeUpState)3443 int8_t ITDS_isWakeUpEvent(WE_sensorInterface_t* sensorInterface, ITDS_state_t *wakeUpState)
3444 {
3445 ITDS_wakeUpEvent_t wakeUpEvent;
3446
3447 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_EVENT_REG, 1, (uint8_t *) &wakeUpEvent))
3448 {
3449 return WE_FAIL;
3450 }
3451
3452 *wakeUpState = (ITDS_state_t) wakeUpEvent.wakeUpState;
3453
3454 return WE_SUCCESS;
3455 }
3456
3457 /**
3458 * @brief Read the free-fall event state [not detected/detected]
3459 * @param[in] sensorInterface Pointer to sensor interface
3460 * @param[out] freeFall The returned free-fall event status.
3461 * @retval Error code
3462 */
ITDS_isFreeFallEvent(WE_sensorInterface_t * sensorInterface,ITDS_state_t * freeFall)3463 int8_t ITDS_isFreeFallEvent(WE_sensorInterface_t* sensorInterface, ITDS_state_t *freeFall)
3464 {
3465 ITDS_wakeUpEvent_t wakeUpEvent;
3466
3467 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_EVENT_REG, 1, (uint8_t *) &wakeUpEvent))
3468 {
3469 return WE_FAIL;
3470 }
3471
3472 *freeFall = (ITDS_state_t) wakeUpEvent.freeFallState;
3473
3474 return WE_SUCCESS;
3475 }
3476
3477
3478 /* TAP EVENT 0x39 */
3479
3480 /**
3481 * @brief Read the overall tap event status
3482 * @param[in] sensorInterface Pointer to sensor interface
3483 * @param[out] status The returned tap event status
3484 * @retval Error code
3485 */
ITDS_getTapEventRegister(WE_sensorInterface_t * sensorInterface,ITDS_tapEvent_t * status)3486 int8_t ITDS_getTapEventRegister(WE_sensorInterface_t* sensorInterface, ITDS_tapEvent_t *status)
3487 {
3488 return ITDS_ReadReg(sensorInterface, ITDS_TAP_EVENT_REG, 1, (uint8_t *) status);
3489 }
3490
3491 /**
3492 * @brief Read the tap event status (tap event on any axis)
3493 * @param[in] sensorInterface Pointer to sensor interface
3494 * @param[out] tapEventState The returned tap event state
3495 * @retval Error code
3496 */
ITDS_isTapEvent(WE_sensorInterface_t * sensorInterface,ITDS_state_t * tapEventState)3497 int8_t ITDS_isTapEvent(WE_sensorInterface_t* sensorInterface, ITDS_state_t *tapEventState)
3498 {
3499 ITDS_tapEvent_t tapEvent;
3500
3501 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_EVENT_REG, 1, (uint8_t *) &tapEvent))
3502 {
3503 return WE_FAIL;
3504 }
3505
3506 *tapEventState = (ITDS_state_t) tapEvent.tapEventState;
3507
3508 return WE_SUCCESS;
3509 }
3510
3511 /**
3512 * @brief Read the tap event acceleration sign (direction of tap event)
3513 * @param[in] sensorInterface Pointer to sensor interface
3514 * @param[out] tapSign The returned tap event acceleration sign
3515 * @retval Error code
3516 */
ITDS_getTapSign(WE_sensorInterface_t * sensorInterface,ITDS_tapSign_t * tapSign)3517 int8_t ITDS_getTapSign(WE_sensorInterface_t* sensorInterface, ITDS_tapSign_t *tapSign)
3518 {
3519 ITDS_tapEvent_t tapEvent;
3520
3521 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_EVENT_REG, 1, (uint8_t *) &tapEvent))
3522 {
3523 return WE_FAIL;
3524 }
3525
3526 *tapSign = (ITDS_tapSign_t) tapEvent.tapSign;
3527
3528 return WE_SUCCESS;
3529 }
3530
3531 /**
3532 * @brief Read the tap event status on axis X
3533 * @param[in] sensorInterface Pointer to sensor interface
3534 * @param[out] tapXAxis The returned tap event status on axis X.
3535 * @retval Error code
3536 */
ITDS_isTapEventXAxis(WE_sensorInterface_t * sensorInterface,ITDS_state_t * tapXAxis)3537 int8_t ITDS_isTapEventXAxis(WE_sensorInterface_t* sensorInterface, ITDS_state_t *tapXAxis)
3538 {
3539 ITDS_tapEvent_t tapEvent;
3540
3541 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_EVENT_REG, 1, (uint8_t *) &tapEvent))
3542 {
3543 return WE_FAIL;
3544 }
3545
3546 *tapXAxis = (ITDS_state_t) tapEvent.tapXAxis;
3547
3548 return WE_SUCCESS;
3549 }
3550
3551 /**
3552 * @brief Read the tap event status on axis Y
3553 * @param[in] sensorInterface Pointer to sensor interface
3554 * @param[out] tapYAxis The returned tap event status on axis Y.
3555 * @retval Error code
3556 */
ITDS_isTapEventYAxis(WE_sensorInterface_t * sensorInterface,ITDS_state_t * tapYAxis)3557 int8_t ITDS_isTapEventYAxis(WE_sensorInterface_t* sensorInterface, ITDS_state_t *tapYAxis)
3558 {
3559 ITDS_tapEvent_t tapEvent;
3560
3561 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_EVENT_REG, 1, (uint8_t *) &tapEvent))
3562 {
3563 return WE_FAIL;
3564 }
3565
3566 *tapYAxis = (ITDS_state_t) tapEvent.tapYAxis;
3567
3568 return WE_SUCCESS;
3569 }
3570
3571 /**
3572 * @brief Read the tap event status on axis Z
3573 * @param[in] sensorInterface Pointer to sensor interface
3574 * @param[out] tapZAxis The returned tap event status on axis Z.
3575 * @retval Error code
3576 */
ITDS_isTapEventZAxis(WE_sensorInterface_t * sensorInterface,ITDS_state_t * tapZAxis)3577 int8_t ITDS_isTapEventZAxis(WE_sensorInterface_t* sensorInterface, ITDS_state_t *tapZAxis)
3578 {
3579 ITDS_tapEvent_t tapEvent;
3580
3581 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_EVENT_REG, 1, (uint8_t *) &tapEvent))
3582 {
3583 return WE_FAIL;
3584 }
3585
3586 *tapZAxis = (ITDS_state_t) tapEvent.tapZAxis;
3587
3588 return WE_SUCCESS;
3589 }
3590
3591
3592 /* 6D_EVENT */
3593
3594 /**
3595 * @brief Read register containing info on 6D orientation change event.
3596 * @param[in] sensorInterface Pointer to sensor interface
3597 * @param[out] status The returned 6D event status.
3598 * @retval Error code
3599 */
ITDS_get6dEventRegister(WE_sensorInterface_t * sensorInterface,ITDS_6dEvent_t * status)3600 int8_t ITDS_get6dEventRegister(WE_sensorInterface_t* sensorInterface, ITDS_6dEvent_t *status)
3601 {
3602 return ITDS_ReadReg(sensorInterface, ITDS_6D_EVENT_REG, 1, (uint8_t *) status);
3603 }
3604
3605 /**
3606 * @brief Check if 6D orientation change event has occurred.
3607 * @param[in] sensorInterface Pointer to sensor interface
3608 * @param[out] orientationChanged The returned 6D orientation change event status
3609 * @retval Error code
3610 */
ITDS_has6dOrientationChanged(WE_sensorInterface_t * sensorInterface,ITDS_state_t * orientationChanged)3611 int8_t ITDS_has6dOrientationChanged(WE_sensorInterface_t* sensorInterface, ITDS_state_t *orientationChanged)
3612 {
3613 ITDS_6dEvent_t event6d;
3614
3615 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_6D_EVENT_REG, 1, (uint8_t *) &event6d))
3616 {
3617 return WE_FAIL;
3618 }
3619
3620 *orientationChanged = (ITDS_state_t) event6d.sixDChange;
3621
3622 return WE_SUCCESS;
3623 }
3624
3625 /**
3626 * @brief Read the XL over threshold state (6D orientation)
3627 * @param[in] sensorInterface Pointer to sensor interface
3628 * @param[out] xlOverThreshold The returned XL over threshold state
3629 * @retval Error code
3630 */
ITDS_isXLOverThreshold(WE_sensorInterface_t * sensorInterface,ITDS_state_t * xlOverThreshold)3631 int8_t ITDS_isXLOverThreshold(WE_sensorInterface_t* sensorInterface, ITDS_state_t *xlOverThreshold)
3632 {
3633 ITDS_6dEvent_t event6d;
3634
3635 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_6D_EVENT_REG, 1, (uint8_t *) &event6d))
3636 {
3637 return WE_FAIL;
3638 }
3639
3640 *xlOverThreshold = (ITDS_state_t) event6d.xlOverThreshold;
3641
3642 return WE_SUCCESS;
3643 }
3644
3645 /**
3646 * @brief Read the XH over threshold state (6D orientation)
3647 * @param[in] sensorInterface Pointer to sensor interface
3648 * @param[out] xhOverThreshold The returned XH over threshold state
3649 * @retval Error code
3650 */
ITDS_isXHOverThreshold(WE_sensorInterface_t * sensorInterface,ITDS_state_t * xhOverThreshold)3651 int8_t ITDS_isXHOverThreshold(WE_sensorInterface_t* sensorInterface, ITDS_state_t *xhOverThreshold)
3652 {
3653 ITDS_6dEvent_t event6d;
3654
3655 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_6D_EVENT_REG, 1, (uint8_t *) &event6d))
3656 {
3657 return WE_FAIL;
3658 }
3659
3660 *xhOverThreshold = (ITDS_state_t) event6d.xhOverThreshold;
3661
3662 return WE_SUCCESS;
3663 }
3664
3665 /**
3666 * @brief Read the YL over threshold state (6D orientation)
3667 * @param[in] sensorInterface Pointer to sensor interface
3668 * @param[out] ylOverThreshold The returned YL over threshold state
3669 * @retval Error code
3670 */
ITDS_isYLOverThreshold(WE_sensorInterface_t * sensorInterface,ITDS_state_t * ylOverThreshold)3671 int8_t ITDS_isYLOverThreshold(WE_sensorInterface_t* sensorInterface, ITDS_state_t *ylOverThreshold)
3672 {
3673 ITDS_6dEvent_t event6d;
3674
3675 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_6D_EVENT_REG, 1, (uint8_t *) &event6d))
3676 {
3677 return WE_FAIL;
3678 }
3679
3680 *ylOverThreshold = (ITDS_state_t) event6d.ylOverThreshold;
3681
3682 return WE_SUCCESS;
3683 }
3684
3685 /**
3686 * @brief Read the YH over threshold state (6D orientation)
3687 * @param[in] sensorInterface Pointer to sensor interface
3688 * @param[out] yhOverThreshold The returned YH over threshold state
3689 * @retval Error code
3690 */
ITDS_isYHOverThreshold(WE_sensorInterface_t * sensorInterface,ITDS_state_t * yhOverThreshold)3691 int8_t ITDS_isYHOverThreshold(WE_sensorInterface_t* sensorInterface, ITDS_state_t *yhOverThreshold)
3692 {
3693 ITDS_6dEvent_t event6d;
3694
3695 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_6D_EVENT_REG, 1, (uint8_t *) &event6d))
3696 {
3697 return WE_FAIL;
3698 }
3699
3700 *yhOverThreshold = (ITDS_state_t) event6d.yhOverThreshold;
3701 return WE_SUCCESS;
3702 }
3703
3704 /**
3705 * @brief Read the ZL over threshold state (6D orientation)
3706 * @param[in] sensorInterface Pointer to sensor interface
3707 * @param[out] zlOverThreshold The returned ZL over threshold state
3708 * @retval Error code
3709 */
ITDS_isZLOverThreshold(WE_sensorInterface_t * sensorInterface,ITDS_state_t * zlOverThreshold)3710 int8_t ITDS_isZLOverThreshold(WE_sensorInterface_t* sensorInterface, ITDS_state_t *zlOverThreshold)
3711 {
3712 ITDS_6dEvent_t event6d;
3713
3714 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_6D_EVENT_REG, 1, (uint8_t *) &event6d))
3715 {
3716 return WE_FAIL;
3717 }
3718
3719 *zlOverThreshold = (ITDS_state_t) event6d.zlOverThreshold;
3720
3721 return WE_SUCCESS;
3722 }
3723
3724 /**
3725 * @brief Read the ZH over threshold state (6D orientation)
3726 * @param[in] sensorInterface Pointer to sensor interface
3727 * @param[out] zhOverThreshold The returned ZH over threshold state
3728 * @retval Error code
3729 */
ITDS_isZHOverThreshold(WE_sensorInterface_t * sensorInterface,ITDS_state_t * zhOverThreshold)3730 int8_t ITDS_isZHOverThreshold(WE_sensorInterface_t* sensorInterface, ITDS_state_t *zhOverThreshold)
3731 {
3732 ITDS_6dEvent_t event6d;
3733
3734 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_6D_EVENT_REG, 1, (uint8_t *) &event6d))
3735 {
3736 return WE_FAIL;
3737 }
3738
3739 *zhOverThreshold = (ITDS_state_t) event6d.zhOverThreshold;
3740
3741 return WE_SUCCESS;
3742 }
3743
3744
3745 /* ALL_INT_EVENT */
3746
3747 /**
3748 * @brief Read register containing info on all interrupt events
3749 * @param[in] sensorInterface Pointer to sensor interface
3750 * @param[out] events The returned interrupt events status
3751 * @retval Error code
3752 */
ITDS_getAllInterruptEvents(WE_sensorInterface_t * sensorInterface,ITDS_allInterruptEvents_t * events)3753 int8_t ITDS_getAllInterruptEvents(WE_sensorInterface_t* sensorInterface, ITDS_allInterruptEvents_t *events)
3754 {
3755 return ITDS_ReadReg(sensorInterface, ITDS_ALL_INT_EVENT_REG, 1, (uint8_t *) events);
3756 }
3757
3758 /**
3759 * @brief Read the sleep change interrupt event state
3760 * @param[in] sensorInterface Pointer to sensor interface
3761 * @param[out] sleep The returned sleep change interrupt event state
3762 * @retval Error code
3763 */
ITDS_isSleepChangeEvent(WE_sensorInterface_t * sensorInterface,ITDS_state_t * sleep)3764 int8_t ITDS_isSleepChangeEvent(WE_sensorInterface_t* sensorInterface, ITDS_state_t *sleep)
3765 {
3766 ITDS_allInterruptEvents_t allInterrupts;
3767
3768 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_ALL_INT_EVENT_REG, 1, (uint8_t *) &allInterrupts))
3769 {
3770 return WE_FAIL;
3771 }
3772
3773 *sleep = (ITDS_state_t) allInterrupts.sleepChangeState;
3774
3775 return WE_SUCCESS;
3776 }
3777
3778
3779 /* X_Y_Z_OFS_USR */
3780
3781 /**
3782 * @brief Set the user offset for axis X (for output data and/or wake-up)
3783 * @param[in] sensorInterface Pointer to sensor interface
3784 * @param[in] offsetValueXAxis User offset for axis X
3785 * @retval Error code
3786 */
ITDS_setOffsetValueX(WE_sensorInterface_t * sensorInterface,int8_t offsetValueXAxis)3787 int8_t ITDS_setOffsetValueX(WE_sensorInterface_t* sensorInterface, int8_t offsetValueXAxis)
3788 {
3789 return ITDS_WriteReg(sensorInterface, ITDS_X_OFS_USR_REG, 1, (uint8_t *) &offsetValueXAxis);
3790 }
3791
3792 /**
3793 * @brief Read the user offset for axis X (for output data and/or wake-up)
3794 * @param[in] sensorInterface Pointer to sensor interface
3795 * @param[out] offsetvalueXAxis The returned user offset for axis X.
3796 * @retval Error code
3797 */
ITDS_getOffsetValueX(WE_sensorInterface_t * sensorInterface,int8_t * offsetvalueXAxis)3798 int8_t ITDS_getOffsetValueX(WE_sensorInterface_t* sensorInterface, int8_t *offsetvalueXAxis)
3799 {
3800 return ITDS_ReadReg(sensorInterface, ITDS_X_OFS_USR_REG, 1, (uint8_t *) offsetvalueXAxis);
3801 }
3802
3803 /**
3804 * @brief Set the user offset for axis Y (for output data and/or wake-up)
3805 * @param[in] sensorInterface Pointer to sensor interface
3806 * @param[in] offsetValueYAxis User offset for axis Y
3807 * @retval Error code
3808 */
ITDS_setOffsetValueY(WE_sensorInterface_t * sensorInterface,int8_t offsetValueYAxis)3809 int8_t ITDS_setOffsetValueY(WE_sensorInterface_t* sensorInterface, int8_t offsetValueYAxis)
3810 {
3811 return ITDS_WriteReg(sensorInterface, ITDS_Y_OFS_USR_REG, 1, (uint8_t *) &offsetValueYAxis);
3812 }
3813
3814 /**
3815 * @brief Read the user offset for axis Y (for output data and/or wake-up)
3816 * @param[in] sensorInterface Pointer to sensor interface
3817 * @param[out] offsetValueYAxis The returned user offset for axis Y.
3818 * @retval Error code
3819 */
ITDS_getOffsetValueY(WE_sensorInterface_t * sensorInterface,int8_t * offsetValueYAxis)3820 int8_t ITDS_getOffsetValueY(WE_sensorInterface_t* sensorInterface, int8_t *offsetValueYAxis)
3821 {
3822 return ITDS_ReadReg(sensorInterface, ITDS_Y_OFS_USR_REG, 1, (uint8_t *) offsetValueYAxis);
3823 }
3824
3825 /**
3826 * @brief Set the user offset for axis Z (for output data and/or wake-up)
3827 * @param[in] sensorInterface Pointer to sensor interface
3828 * @param[in] offsetvalueZAxis The user offset for axis Z
3829 * @retval Error code
3830 */
ITDS_setOffsetValueZ(WE_sensorInterface_t * sensorInterface,int8_t offsetvalueZAxis)3831 int8_t ITDS_setOffsetValueZ(WE_sensorInterface_t* sensorInterface, int8_t offsetvalueZAxis)
3832 {
3833 return ITDS_WriteReg(sensorInterface, ITDS_Z_OFS_USR_REG, 1, (uint8_t *) &offsetvalueZAxis);
3834 }
3835
3836 /**
3837 * @brief Read the user offset for axis Z (for output data and/or wake-up)
3838 * @param[in] sensorInterface Pointer to sensor interface
3839 * @param[out] offsetValueZAxis The returned user offset for axis Z.
3840 * @retval Error code
3841 */
ITDS_getOffsetValueZ(WE_sensorInterface_t * sensorInterface,int8_t * offsetValueZAxis)3842 int8_t ITDS_getOffsetValueZ(WE_sensorInterface_t* sensorInterface, int8_t *offsetValueZAxis)
3843 {
3844 return ITDS_ReadReg(sensorInterface, ITDS_Z_OFS_USR_REG, 1, (uint8_t *) offsetValueZAxis);
3845 }
3846
3847
3848 /* CTRL_7 */
3849
3850 /**
3851 * @brief Select the data ready interrupt mode [latched mode / pulsed mode]
3852 * @param[in] sensorInterface Pointer to sensor interface
3853 * @param[in] drdyPulsed Data ready interrupt mode
3854 * @retval Error code
3855 */
ITDS_setDataReadyPulsed(WE_sensorInterface_t * sensorInterface,ITDS_drdyPulse_t drdyPulsed)3856 int8_t ITDS_setDataReadyPulsed(WE_sensorInterface_t* sensorInterface, ITDS_drdyPulse_t drdyPulsed)
3857 {
3858 ITDS_ctrl7_t ctrl7;
3859
3860 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
3861 {
3862 return WE_FAIL;
3863 }
3864
3865 ctrl7.drdyPulse = drdyPulsed;
3866
3867 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7);
3868 }
3869
3870 /**
3871 * @brief Read the data ready interrupt mode [latched mode / pulsed mode]
3872 * @param[in] sensorInterface Pointer to sensor interface
3873 * @param[out] drdyPulsed The returned data ready interrupt mode
3874 * @retval Error code
3875 */
ITDS_isDataReadyPulsed(WE_sensorInterface_t * sensorInterface,ITDS_drdyPulse_t * drdyPulsed)3876 int8_t ITDS_isDataReadyPulsed(WE_sensorInterface_t* sensorInterface, ITDS_drdyPulse_t *drdyPulsed)
3877 {
3878 ITDS_ctrl7_t ctrl7;
3879
3880 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
3881 {
3882 return WE_FAIL;
3883 }
3884
3885 *drdyPulsed = (ITDS_drdyPulse_t) ctrl7.drdyPulse;
3886
3887 return WE_SUCCESS;
3888 }
3889
3890 /**
3891 * @brief Enable signal routing from INT_1 to INT_0
3892 * @param[in] sensorInterface Pointer to sensor interface
3893 * @param[in] int1OnInt0 Signal routing INT_1 to INT_0 state
3894 * @retval Error code
3895 */
ITDS_setInt1OnInt0(WE_sensorInterface_t * sensorInterface,ITDS_state_t int1OnInt0)3896 int8_t ITDS_setInt1OnInt0(WE_sensorInterface_t* sensorInterface, ITDS_state_t int1OnInt0)
3897 {
3898 ITDS_ctrl7_t ctrl7;
3899
3900 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
3901 {
3902 return WE_FAIL;
3903 }
3904
3905 ctrl7.INT1toINT0 = int1OnInt0;
3906
3907 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7);
3908 }
3909
3910 /**
3911 * @brief Check if signal routing from INT_1 to INT_0 is enabled
3912 * @param[in] sensorInterface Pointer to sensor interface
3913 * @param[out] int1OnInt0 The returned routing enable state.
3914 * @retval Error code
3915 */
ITDS_getInt1OnInt0(WE_sensorInterface_t * sensorInterface,ITDS_state_t * int1OnInt0)3916 int8_t ITDS_getInt1OnInt0(WE_sensorInterface_t* sensorInterface, ITDS_state_t *int1OnInt0)
3917 {
3918 ITDS_ctrl7_t ctrl7;
3919
3920 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
3921 {
3922 return WE_FAIL;
3923 }
3924
3925 *int1OnInt0 = (ITDS_state_t) ctrl7.INT1toINT0;
3926
3927 return WE_SUCCESS;
3928 }
3929
3930 /**
3931 * @brief Enable/disable interrupts
3932 * @param[in] sensorInterface Pointer to sensor interface
3933 * @param[in] interrupts Interrupts enable state
3934 * @retval Error code
3935 */
ITDS_enableInterrupts(WE_sensorInterface_t * sensorInterface,ITDS_state_t interrupts)3936 int8_t ITDS_enableInterrupts(WE_sensorInterface_t* sensorInterface, ITDS_state_t interrupts)
3937 {
3938 ITDS_ctrl7_t ctrl7;
3939
3940 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
3941 {
3942 return WE_FAIL;
3943 }
3944
3945 ctrl7.enInterrupts = interrupts;
3946
3947 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7);
3948 }
3949
3950 /**
3951 * @brief Check if interrupts are enabled
3952 * @param[in] sensorInterface Pointer to sensor interface
3953 * @param[out] interrupts The returned interrupts enable state.
3954 * @retval Error code
3955 */
ITDS_areInterruptsEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * interrupts)3956 int8_t ITDS_areInterruptsEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *interrupts)
3957 {
3958 ITDS_ctrl7_t ctrl7;
3959
3960 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
3961 {
3962 return WE_FAIL;
3963 }
3964
3965 *interrupts = (ITDS_state_t) ctrl7.enInterrupts;
3966
3967 return WE_SUCCESS;
3968 }
3969
3970 /**
3971 * @brief Enable/disable the application of the user offset values to output data
3972 * @param[in] sensorInterface Pointer to sensor interface
3973 * @param[in] applyOffset State
3974 * @retval Error code
3975 */
ITDS_enableApplyOffset(WE_sensorInterface_t * sensorInterface,ITDS_state_t applyOffset)3976 int8_t ITDS_enableApplyOffset(WE_sensorInterface_t* sensorInterface, ITDS_state_t applyOffset)
3977 {
3978 ITDS_ctrl7_t ctrl7;
3979
3980 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
3981 {
3982 return WE_FAIL;
3983 }
3984
3985 ctrl7.applyOffset = applyOffset;
3986
3987 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7);
3988 }
3989
3990 /**
3991 * @brief Check if application of user offset values to output data is enabled.
3992 * @param[in] sensorInterface Pointer to sensor interface
3993 * @param[out] applyOffset Returned enable state.
3994 * @retval Error code
3995 */
ITDS_isApplyOffsetEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * applyOffset)3996 int8_t ITDS_isApplyOffsetEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *applyOffset)
3997 {
3998 ITDS_ctrl7_t ctrl7;
3999
4000 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
4001 {
4002 return WE_FAIL;
4003 }
4004
4005 *applyOffset = (ITDS_state_t) ctrl7.applyOffset;
4006
4007 return WE_SUCCESS;
4008 }
4009
4010 /**
4011 * @brief Enable/disable the application of user offset values to data only for wake-up functions
4012 * @param[in] sensorInterface Pointer to sensor interface
4013 * @param[in] applyOffset State
4014 * @retval Error code
4015 */
ITDS_enableApplyWakeUpOffset(WE_sensorInterface_t * sensorInterface,ITDS_state_t applyOffset)4016 int8_t ITDS_enableApplyWakeUpOffset(WE_sensorInterface_t* sensorInterface, ITDS_state_t applyOffset)
4017 {
4018 ITDS_ctrl7_t ctrl7;
4019
4020 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
4021 {
4022 return WE_FAIL;
4023 }
4024
4025 ctrl7.applyWakeUpOffset = applyOffset;
4026
4027 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7);
4028 }
4029
4030 /**
4031 * @brief Check if application user offset values to data only for wake-up functions is enabled
4032 * @param[in] sensorInterface Pointer to sensor interface
4033 * @param[out] applyOffset The returned enable state
4034 * @retval Error code
4035 */
ITDS_isApplyWakeUpOffsetEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * applyOffset)4036 int8_t ITDS_isApplyWakeUpOffsetEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *applyOffset)
4037 {
4038 ITDS_ctrl7_t ctrl7;
4039
4040 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
4041 {
4042 return WE_FAIL;
4043 }
4044
4045 *applyOffset = (ITDS_state_t) ctrl7.applyWakeUpOffset;
4046
4047 return WE_SUCCESS;
4048 }
4049
4050 /**
4051 * @brief Set the weight of the user offset words
4052 * @param[in] sensorInterface Pointer to sensor interface
4053 * @param[in] offsetWeight Offset weight
4054 * @retval Error code
4055 */
ITDS_setOffsetWeight(WE_sensorInterface_t * sensorInterface,ITDS_state_t offsetWeight)4056 int8_t ITDS_setOffsetWeight(WE_sensorInterface_t* sensorInterface, ITDS_state_t offsetWeight)
4057 {
4058 ITDS_ctrl7_t ctrl7;
4059
4060 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
4061 {
4062 return WE_FAIL;
4063 }
4064
4065 ctrl7.userOffset = offsetWeight;
4066
4067 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7);
4068 }
4069
4070 /**
4071 * @brief Read the weight of the user offset words
4072 * @param[in] sensorInterface Pointer to sensor interface
4073 * @param[out] offsetWeight The returned offset weight.
4074 * @retval Error code
4075 */
ITDS_getOffsetWeight(WE_sensorInterface_t * sensorInterface,ITDS_state_t * offsetWeight)4076 int8_t ITDS_getOffsetWeight(WE_sensorInterface_t* sensorInterface, ITDS_state_t *offsetWeight)
4077 {
4078 ITDS_ctrl7_t ctrl7;
4079
4080 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
4081 {
4082 return WE_FAIL;
4083 }
4084
4085 *offsetWeight = (ITDS_state_t) ctrl7.userOffset;
4086
4087 return WE_SUCCESS;
4088 }
4089
4090 /**
4091 * @brief Enable/disable high pass filter reference mode
4092 * @param[in] sensorInterface Pointer to sensor interface
4093 * @param[in] refMode State
4094 * @retval Error code
4095 */
ITDS_enableHighPassRefMode(WE_sensorInterface_t * sensorInterface,ITDS_state_t refMode)4096 int8_t ITDS_enableHighPassRefMode(WE_sensorInterface_t* sensorInterface, ITDS_state_t refMode)
4097 {
4098 ITDS_ctrl7_t ctrl7;
4099
4100 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
4101 {
4102 return WE_FAIL;
4103 }
4104
4105 ctrl7.highPassRefMode = refMode;
4106
4107 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7);
4108 }
4109
4110 /**
4111 * @brief Check if high pass filter reference mode is enabled
4112 * @param[in] sensorInterface Pointer to sensor interface
4113 * @param[out] refMode The returned reference mode state
4114 * @retval Error code
4115 */
ITDS_isHighPassRefModeEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * refMode)4116 int8_t ITDS_isHighPassRefModeEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *refMode)
4117 {
4118 ITDS_ctrl7_t ctrl7;
4119
4120 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
4121 {
4122 return WE_FAIL;
4123 }
4124
4125 *refMode = (ITDS_state_t) ctrl7.highPassRefMode;
4126
4127 return WE_SUCCESS;
4128 }
4129
4130 /**
4131 * @brief Enable/disable the low pass filter for 6D orientation detection
4132 * @param[in] sensorInterface Pointer to sensor interface
4133 * @param[in] lowPassOn6D Low pass filter enable state
4134 * @retval Error code
4135 */
ITDS_enableLowPassOn6D(WE_sensorInterface_t * sensorInterface,ITDS_state_t lowPassOn6D)4136 int8_t ITDS_enableLowPassOn6D(WE_sensorInterface_t* sensorInterface, ITDS_state_t lowPassOn6D)
4137 {
4138 ITDS_ctrl7_t ctrl7;
4139
4140 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
4141 {
4142 return WE_FAIL;
4143 }
4144
4145 ctrl7.lowPassOn6D = lowPassOn6D;
4146
4147 return ITDS_WriteReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7);
4148 }
4149
4150 /**
4151 * @brief Check if the low pass filter for 6D orientation detection is enabled
4152 * @param[in] sensorInterface Pointer to sensor interface
4153 * @param[out] lowPassOn6D The returned low pass filter enable state
4154 * @retval Error code
4155 */
ITDS_isLowPassOn6DEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * lowPassOn6D)4156 int8_t ITDS_isLowPassOn6DEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *lowPassOn6D)
4157 {
4158 ITDS_ctrl7_t ctrl7;
4159
4160 if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
4161 {
4162 return WE_FAIL;
4163 }
4164
4165 *lowPassOn6D = (ITDS_state_t) ctrl7.lowPassOn6D;
4166
4167 return WE_SUCCESS;
4168 }
4169