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-2533020201601 sensor.
10  */
11 
12 #include "WSEN_ITDS_2533020201601_hal.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, .protocol = WE_i2cProtocol_RegisterBased, .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 
1777 #ifdef WE_USE_FLOAT
1778 
1779 /**
1780  * @brief Reads the X axis acceleration in [mg].
1781  *
1782  * Note that this functions relies on the current full scale value.
1783  * Make sure that the current full scale value is known by calling
1784  * ITDS_setFullScale() or ITDS_getFullScale() at least once prior to
1785  * calling this function.
1786  *
1787  * @param[in] sensorInterface Pointer to sensor interface
1788  * @param[out] xAcc X axis acceleration value in [mg]
1789  * @retval Error code
1790  */
ITDS_getAccelerationX_float(WE_sensorInterface_t * sensorInterface,float * xAcc)1791 int8_t ITDS_getAccelerationX_float(WE_sensorInterface_t* sensorInterface, float *xAcc)
1792 {
1793   int16_t rawAcc;
1794   if (WE_FAIL == ITDS_getRawAccelerationX(sensorInterface, &rawAcc))
1795   {
1796     return WE_FAIL;
1797   }
1798   *xAcc = ITDS_convertAcceleration_float(rawAcc, currentFullScale);
1799   return WE_SUCCESS;
1800 }
1801 
1802 /**
1803  * @brief Reads the Y axis acceleration in [mg].
1804  *
1805  * Note that this functions relies on the current full scale value.
1806  * Make sure that the current full scale value is known by calling
1807  * ITDS_setFullScale() or ITDS_getFullScale() at least once prior to
1808  * calling this function.
1809  *
1810  * @param[in] sensorInterface Pointer to sensor interface
1811  * @param[out] yAcc Y axis acceleration value in [mg]
1812  * @retval Error code
1813  */
ITDS_getAccelerationY_float(WE_sensorInterface_t * sensorInterface,float * yAcc)1814 int8_t ITDS_getAccelerationY_float(WE_sensorInterface_t* sensorInterface, float *yAcc)
1815 {
1816   int16_t rawAcc;
1817   if (WE_FAIL == ITDS_getRawAccelerationY(sensorInterface, &rawAcc))
1818   {
1819     return WE_FAIL;
1820   }
1821   *yAcc = ITDS_convertAcceleration_float(rawAcc, currentFullScale);
1822   return WE_SUCCESS;
1823 }
1824 
1825 /**
1826  * @brief Reads the Z axis acceleration in [mg].
1827  *
1828  * Note that this functions relies on the current full scale value.
1829  * Make sure that the current full scale value is known by calling
1830  * ITDS_setFullScale() or ITDS_getFullScale() at least once prior to
1831  * calling this function.
1832  *
1833  * @param[in] sensorInterface Pointer to sensor interface
1834  * @param[out] zAcc Z axis acceleration value in [mg]
1835  * @retval Error code
1836  */
ITDS_getAccelerationZ_float(WE_sensorInterface_t * sensorInterface,float * zAcc)1837 int8_t ITDS_getAccelerationZ_float(WE_sensorInterface_t* sensorInterface, float *zAcc)
1838 {
1839   int16_t rawAcc;
1840   if (WE_FAIL == ITDS_getRawAccelerationZ(sensorInterface, &rawAcc))
1841   {
1842     return WE_FAIL;
1843   }
1844   *zAcc = ITDS_convertAcceleration_float(rawAcc, currentFullScale);
1845   return WE_SUCCESS;
1846 }
1847 
1848 /**
1849  * @brief Returns one or more acceleration samples in [mg] for all axes.
1850  *
1851  * Note that this functions relies on the current full scale value.
1852  * Make sure that the current full scale value is known by calling
1853  * ITDS_setFullScale() or ITDS_getFullScale() at least once prior to
1854  * calling this function.
1855  *
1856  * @param[in] sensorInterface Pointer to sensor interface
1857  * @param[in] numSamples Number of samples to be read (1-32)
1858  * @param[out] xAcc X-axis acceleration in [mg]
1859  * @param[out] yAcc Y-axis acceleration in [mg]
1860  * @param[out] zAcc Z-axis acceleration in [mg]
1861  * @retval Error code
1862  */
ITDS_getAccelerations_float(WE_sensorInterface_t * sensorInterface,uint8_t numSamples,float * xAcc,float * yAcc,float * zAcc)1863 int8_t ITDS_getAccelerations_float(WE_sensorInterface_t* sensorInterface,
1864                                    uint8_t numSamples,
1865                                    float *xAcc,
1866                                    float *yAcc,
1867                                    float *zAcc)
1868 {
1869   /* Max. buffer size is 192 (32 slot, 16 bit values) */
1870   uint8_t buffer[192];
1871 
1872   if (numSamples > 32)
1873   {
1874     return WE_FAIL;
1875   }
1876 
1877   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_X_OUT_L_REG, 3 * 2 * numSamples, buffer))
1878   {
1879     return WE_FAIL;
1880   }
1881 
1882   uint16_t sample;
1883   uint8_t *bufferPtr = buffer;
1884   for (uint8_t i = 0; i < numSamples; i++)
1885   {
1886     sample = ((int16_t) *bufferPtr);
1887     bufferPtr++;
1888     sample |= (int16_t) ((*bufferPtr) << 8);
1889     bufferPtr++;
1890     xAcc[i] = ITDS_convertAcceleration_float((int16_t) sample, currentFullScale);
1891 
1892     sample = ((int16_t) *bufferPtr);
1893     bufferPtr++;
1894     sample |= (int16_t) ((*bufferPtr) << 8);
1895     bufferPtr++;
1896     yAcc[i] = ITDS_convertAcceleration_float((int16_t) sample, currentFullScale);
1897 
1898     sample = ((int16_t) *bufferPtr);
1899     bufferPtr++;
1900     sample |= (int16_t) ((*bufferPtr) << 8);
1901     bufferPtr++;
1902     zAcc[i] = ITDS_convertAcceleration_float((int16_t) sample, currentFullScale);
1903   }
1904 
1905   return WE_SUCCESS;
1906 }
1907 
1908 /**
1909  * @brief Converts the supplied raw acceleration into [mg]
1910  * @param[in] acc Raw acceleration value (accelerometer output)
1911  * @param[in] fullScale Accelerometer full scale
1912  * @retval The converted acceleration in [mg]
1913  */
ITDS_convertAcceleration_float(int16_t acc,ITDS_fullScale_t fullScale)1914 float ITDS_convertAcceleration_float(int16_t acc, ITDS_fullScale_t fullScale)
1915 {
1916   switch (fullScale)
1917   {
1918   case ITDS_twoG:
1919     return ITDS_convertAccelerationFs2g_float(acc);
1920 
1921   case ITDS_fourG:
1922     return ITDS_convertAccelerationFs4g_float(acc);
1923 
1924   case ITDS_eightG:
1925     return ITDS_convertAccelerationFs8g_float(acc);
1926 
1927   case ITDS_sixteenG:
1928     return ITDS_convertAccelerationFs16g_float(acc);
1929 
1930   default:
1931     break;
1932   }
1933 
1934   return 0;
1935 }
1936 
1937 /**
1938  * @brief Converts the supplied raw acceleration sampled using
1939  * ITDS_twoG to [mg]
1940  * this operation uses a common factor that already
1941  * includes  the shift by 2 (for 14 bit mode) or the shift by 4 (for 12 bit,
1942  * i.e. "low power mode 1") with their respective sensitivity values.
1943  * The applied conversion factor for Full_Scale 2G is valid for
1944  * "low power mode 1" (CTRL_1.LP_Mode = '01') as well as for
1945  * "not low power mode 1" (CTRL_1.LP_Mode != '01') power modes.
1946  *
1947  * @param[in] acc Raw acceleration value (accelerometer output)
1948  * @retval The converted acceleration in [mg]
1949  */
ITDS_convertAccelerationFs2g_float(int16_t acc)1950 float ITDS_convertAccelerationFs2g_float(int16_t acc)
1951 {
1952   return ((float) acc) * 0.061f;
1953 }
1954 
1955 /**
1956  * @brief Converts the supplied raw acceleration sampled using
1957  * ITDS_fourG to [mg]
1958  * this operation uses a common factor that already
1959  * includes  the shift by 2 (for 14 bit mode) or the shift by 4 (for 12 bit,
1960  * i.e. "low power mode 1") with their respective sensitivity values.
1961  * The applied conversion factor for Full_Scale 4G is valid for
1962  * "low power mode 1" (CTRL_1.LP_Mode = '01') as well as for
1963  * "not low power mode 1" (CTRL_1.LP_Mode != '01') power modes.
1964  *
1965  * @param[in] acc Raw acceleration value (accelerometer output)
1966  * @retval The converted acceleration in [mg]
1967  */
ITDS_convertAccelerationFs4g_float(int16_t acc)1968 float ITDS_convertAccelerationFs4g_float(int16_t acc)
1969 {
1970   return ((float) acc) * 0.122f;
1971 }
1972 
1973 /**
1974  * @brief Converts the supplied raw acceleration sampled using
1975  * ITDS_eightG to [mg]
1976  * this operation uses a common factor that already
1977  * includes  the shift by 2 (for 14 bit mode) or the shift by 4 (for 12 bit,
1978  * i.e. "low power mode 1") with their respective sensitivity values.
1979  * The applied conversion factor for Full_Scale 8G is valid for
1980  * "low power mode 1" (CTRL_1.LP_Mode = '01') as well as for
1981  * "not low power mode 1" (CTRL_1.LP_Mode != '01') power modes.
1982  *
1983  * @param[in] acc Raw acceleration value (accelerometer output)
1984  * @retval The converted acceleration in [mg]
1985  */
ITDS_convertAccelerationFs8g_float(int16_t acc)1986 float ITDS_convertAccelerationFs8g_float(int16_t acc)
1987 {
1988   return ((float) acc) * 0.244f;
1989 }
1990 
1991 /**
1992  * @brief Converts the supplied raw acceleration sampled using
1993  * ITDS_sixteenG to [mg]
1994  * this operation uses a common factor that already
1995  * includes  the shift by 2 (for 14 bit mode) or the shift by 4 (for 12 bit,
1996  * i.e. "low power mode 1") with their respective sensitivity values.
1997  * The applied conversion factor for Full_Scale 16G is valid for
1998  * "low power mode 1" (CTRL_1.LP_Mode = '01') as well as for
1999  * "not low power mode 1" (CTRL_1.LP_Mode != '01') power modes.
2000  *
2001  * @param[in] acc Raw acceleration value (accelerometer output)
2002  * @retval The converted acceleration in [mg]
2003  */
ITDS_convertAccelerationFs16g_float(int16_t acc)2004 float ITDS_convertAccelerationFs16g_float(int16_t acc)
2005 {
2006   return ((float) acc) * 0.488f;
2007 }
2008 #endif /* WE_USE_FLOAT */
2009 
2010 
2011 /**
2012  * @brief Reads the X axis acceleration in [mg].
2013  *
2014  * Note that this functions relies on the current full scale value.
2015  * Make sure that the current full scale value is known by calling
2016  * ITDS_setFullScale() or ITDS_getFullScale() at least once prior to
2017  * calling this function.
2018  *
2019  * @param[in] sensorInterface Pointer to sensor interface
2020  * @param[out] xAcc X axis acceleration value in [mg]
2021  * @retval Error code
2022  */
ITDS_getAccelerationX_int(WE_sensorInterface_t * sensorInterface,int16_t * xAcc)2023 int8_t ITDS_getAccelerationX_int(WE_sensorInterface_t* sensorInterface, int16_t *xAcc)
2024 {
2025   int16_t rawAcc;
2026   if (WE_FAIL == ITDS_getRawAccelerationX(sensorInterface, &rawAcc))
2027   {
2028     return WE_FAIL;
2029   }
2030   *xAcc = ITDS_convertAcceleration_int(rawAcc, currentFullScale);
2031   return WE_SUCCESS;
2032 }
2033 
2034 /**
2035  * @brief Reads the Y axis acceleration in [mg].
2036  *
2037  * Note that this functions relies on the current full scale value.
2038  * Make sure that the current full scale value is known by calling
2039  * ITDS_setFullScale() or ITDS_getFullScale() at least once prior to
2040  * calling this function.
2041  *
2042  * @param[in] sensorInterface Pointer to sensor interface
2043  * @param[out] yAcc Y axis acceleration value in [mg]
2044  * @retval Error code
2045  */
ITDS_getAccelerationY_int(WE_sensorInterface_t * sensorInterface,int16_t * yAcc)2046 int8_t ITDS_getAccelerationY_int(WE_sensorInterface_t* sensorInterface, int16_t *yAcc)
2047 {
2048   int16_t rawAcc;
2049   if (WE_FAIL == ITDS_getRawAccelerationY(sensorInterface, &rawAcc))
2050   {
2051     return WE_FAIL;
2052   }
2053   *yAcc = ITDS_convertAcceleration_int(rawAcc, currentFullScale);
2054   return WE_SUCCESS;
2055 }
2056 
2057 /**
2058  * @brief Reads the Z axis acceleration in [mg].
2059  *
2060  * Note that this functions relies on the current full scale value.
2061  * Make sure that the current full scale value is known by calling
2062  * ITDS_setFullScale() or ITDS_getFullScale() at least once prior to
2063  * calling this function.
2064  *
2065  * @param[in] sensorInterface Pointer to sensor interface
2066  * @param[out] zAcc Z axis acceleration value in [mg]
2067  * @retval Error code
2068  */
ITDS_getAccelerationZ_int(WE_sensorInterface_t * sensorInterface,int16_t * zAcc)2069 int8_t ITDS_getAccelerationZ_int(WE_sensorInterface_t* sensorInterface, int16_t *zAcc)
2070 {
2071   int16_t rawAcc;
2072   if (WE_FAIL == ITDS_getRawAccelerationZ(sensorInterface, &rawAcc))
2073   {
2074     return WE_FAIL;
2075   }
2076   *zAcc = ITDS_convertAcceleration_int(rawAcc, currentFullScale);
2077   return WE_SUCCESS;
2078 }
2079 
2080 /**
2081  * @brief Returns one or more acceleration samples in [mg] for all axes.
2082  *
2083  * Note that this functions relies on the current full scale value.
2084  * Make sure that the current full scale value is known by calling
2085  * ITDS_setFullScale() or ITDS_getFullScale() at least once prior to
2086  * calling this function.
2087  *
2088  * @param[in] sensorInterface Pointer to sensor interface
2089  * @param[in] numSamples Number of samples to be read (1-32)
2090  * @param[out] xAcc X-axis acceleration in [mg]
2091  * @param[out] yAcc Y-axis acceleration in [mg]
2092  * @param[out] zAcc Z-axis acceleration in [mg]
2093  * @retval Error code
2094  */
ITDS_getAccelerations_int(WE_sensorInterface_t * sensorInterface,uint8_t numSamples,int16_t * xAcc,int16_t * yAcc,int16_t * zAcc)2095 int8_t ITDS_getAccelerations_int(WE_sensorInterface_t* sensorInterface,
2096                                  uint8_t numSamples,
2097                                  int16_t *xAcc,
2098                                  int16_t *yAcc,
2099                                  int16_t *zAcc)
2100 {
2101   /* Max. buffer size is 192 (32 slot, 16 bit values) */
2102   uint8_t buffer[192];
2103 
2104   if (numSamples > 32)
2105   {
2106     return WE_FAIL;
2107   }
2108 
2109   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_X_OUT_L_REG, 3 * 2 * numSamples, buffer))
2110   {
2111     return WE_FAIL;
2112   }
2113 
2114   uint16_t sample;
2115   uint8_t *bufferPtr = buffer;
2116   for (uint8_t i = 0; i < numSamples; i++)
2117   {
2118     sample = ((int16_t) *bufferPtr);
2119     bufferPtr++;
2120     sample |= (int16_t) ((*bufferPtr) << 8);
2121     bufferPtr++;
2122     xAcc[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     yAcc[i] = ITDS_convertAcceleration_int((int16_t) sample, currentFullScale);
2129 
2130     sample = ((int16_t) *bufferPtr);
2131     bufferPtr++;
2132     sample |= (int16_t) ((*bufferPtr) << 8);
2133     bufferPtr++;
2134     zAcc[i] = ITDS_convertAcceleration_int((int16_t) sample, currentFullScale);
2135   }
2136 
2137   return WE_SUCCESS;
2138 }
2139 
2140 /**
2141  * @brief Converts the supplied raw acceleration into [mg]
2142  * @param[in] acc Raw acceleration value (accelerometer output)
2143  * @param[in] fullScale Accelerometer full scale
2144  * @retval The converted acceleration in [mg]
2145  */
ITDS_convertAcceleration_int(int16_t acc,ITDS_fullScale_t fullScale)2146 int16_t ITDS_convertAcceleration_int(int16_t acc, ITDS_fullScale_t fullScale)
2147 {
2148   switch (fullScale)
2149   {
2150   case ITDS_twoG:
2151     return ITDS_convertAccelerationFs2g_int(acc);
2152 
2153   case ITDS_sixteenG:
2154     return ITDS_convertAccelerationFs16g_int(acc);
2155 
2156   case ITDS_fourG:
2157     return ITDS_convertAccelerationFs4g_int(acc);
2158 
2159   case ITDS_eightG:
2160     return ITDS_convertAccelerationFs8g_int(acc);
2161 
2162   default:
2163     return 0;
2164   }
2165 }
2166 
2167 /**
2168  * @brief Converts the supplied raw acceleration sampled using
2169  * ITDS_twoG to [mg]
2170  * @param[in] acc Raw acceleration value (accelerometer output)
2171  * @retval The converted acceleration in [mg]
2172  */
ITDS_convertAccelerationFs2g_int(int16_t acc)2173 int16_t ITDS_convertAccelerationFs2g_int(int16_t acc)
2174 {
2175   return (int16_t) ((((int32_t) acc) * 61) / 1000);
2176 }
2177 
2178 /**
2179  * @brief Converts the supplied raw acceleration sampled using
2180  * ITDS_fourG to [mg]
2181  * @param[in] acc Raw acceleration value (accelerometer output)
2182  * @retval The converted acceleration in [mg]
2183  */
ITDS_convertAccelerationFs4g_int(int16_t acc)2184 int16_t ITDS_convertAccelerationFs4g_int(int16_t acc)
2185 {
2186   return (int16_t) ((((int32_t) acc) * 122) / 1000);
2187 }
2188 
2189 /**
2190  * @brief Converts the supplied raw acceleration sampled using
2191  * ITDS_eightG to [mg]
2192  * @param[in] acc Raw acceleration value (accelerometer output)
2193  * @retval The converted acceleration in [mg]
2194  */
ITDS_convertAccelerationFs8g_int(int16_t acc)2195 int16_t ITDS_convertAccelerationFs8g_int(int16_t acc)
2196 {
2197   return (int16_t) ((((int32_t) acc) * 244) / 1000);
2198 }
2199 
2200 /**
2201  * @brief Converts the supplied raw acceleration sampled using
2202  * ITDS_sixteenG to [mg]
2203  * @param[in] acc Raw acceleration value (accelerometer output)
2204  * @retval The converted acceleration in [mg]
2205  */
ITDS_convertAccelerationFs16g_int(int16_t acc)2206 int16_t ITDS_convertAccelerationFs16g_int(int16_t acc)
2207 {
2208   return (int16_t) ((((int32_t) acc) * 488) / 1000);
2209 }
2210 
2211 
2212 /* ITDS_T_OUT_REG */
2213 
2214 /**
2215  * @brief Read the 8 bit temperature
2216  * @param[in] sensorInterface Pointer to sensor interface
2217  * @param[out] temp8bit The returned temperature
2218  * @retval Error code
2219  */
2220 
ITDS_getTemperature8bit(WE_sensorInterface_t * sensorInterface,uint8_t * temp8bit)2221 int8_t ITDS_getTemperature8bit(WE_sensorInterface_t* sensorInterface, uint8_t *temp8bit)
2222 {
2223   uint8_t temperatureValue8bit;
2224   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_T_OUT_REG, 1, &temperatureValue8bit))
2225   {
2226     return WE_FAIL;
2227   }
2228 
2229   *temp8bit = temperatureValue8bit;
2230   return WE_SUCCESS;
2231 }
2232 
2233 /**
2234  * @brief Read the 12 bit temperature
2235  * @param[in] sensorInterface Pointer to sensor interface
2236  * @param[out] temp12bit The returned temperature
2237  * @retval Error code
2238  */
ITDS_getRawTemperature12bit(WE_sensorInterface_t * sensorInterface,int16_t * temp12bit)2239 int8_t  ITDS_getRawTemperature12bit(WE_sensorInterface_t* sensorInterface, int16_t *temp12bit)
2240 {
2241   uint8_t temp[2] = {0};
2242 
2243   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_T_OUT_L_REG, 2, temp))
2244   {
2245     return WE_FAIL;
2246   }
2247 
2248   *temp12bit = (int16_t) (temp[1] << 8);
2249   *temp12bit |= (int16_t) temp[0];
2250 
2251   *temp12bit = (*temp12bit) >> 4;
2252 
2253   return WE_SUCCESS;
2254 }
2255 
2256 #ifdef WE_USE_FLOAT
2257 
2258 /**
2259  * @brief Read the 12 bit temperature in °C
2260  * @param[in] sensorInterface Pointer to sensor interface
2261  * @param[out] tempDegC The returned temperature
2262  * @retval Error code
2263  */
ITDS_getTemperature12bit(WE_sensorInterface_t * sensorInterface,float * tempDegC)2264 int8_t  ITDS_getTemperature12bit(WE_sensorInterface_t* sensorInterface, float *tempDegC)
2265 {
2266   int16_t rawTemp = 0;
2267   if (WE_SUCCESS == ITDS_getRawTemperature12bit(sensorInterface, &rawTemp))
2268   {
2269     *tempDegC = (((float) rawTemp) / 16.0f) + 25.0f;
2270   }
2271   else
2272   {
2273     return WE_FAIL;
2274   }
2275   return WE_SUCCESS;
2276 }
2277 
2278 #endif /* WE_USE_FLOAT */
2279 
2280 
2281 /* FIFO_CTRL (0x2E) */
2282 
2283 /**
2284  * @brief Set the FIFO threshold of the sensor
2285  * @param[in] sensorInterface Pointer to sensor interface
2286  * @param[in] fifoThreshold FIFO threshold (value between 0 and 31)
2287  * @retval Error code
2288  */
ITDS_setFifoThreshold(WE_sensorInterface_t * sensorInterface,uint8_t fifoThreshold)2289 int8_t ITDS_setFifoThreshold(WE_sensorInterface_t* sensorInterface, uint8_t fifoThreshold)
2290 {
2291   ITDS_fifoCtrl_t fifoCtrl;
2292 
2293   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_FIFO_CTRL_REG, 1, (uint8_t *) &fifoCtrl))
2294   {
2295     return WE_FAIL;
2296   }
2297 
2298   fifoCtrl.fifoThresholdLevel = fifoThreshold;
2299 
2300   return ITDS_WriteReg(sensorInterface, ITDS_FIFO_CTRL_REG, 1, (uint8_t *) &fifoCtrl);
2301 }
2302 
2303 /**
2304  * @brief Read the FIFO threshold
2305  * @param[in] sensorInterface Pointer to sensor interface
2306  * @param[out] fifoThreshold The returned FIFO threshold (value between 0 and 31)
2307  * @retval Error code
2308  */
ITDS_getFifoThreshold(WE_sensorInterface_t * sensorInterface,uint8_t * fifoThreshold)2309 int8_t ITDS_getFifoThreshold(WE_sensorInterface_t* sensorInterface, uint8_t *fifoThreshold)
2310 {
2311   ITDS_fifoCtrl_t fifoCtrl;
2312 
2313   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_FIFO_CTRL_REG, 1, (uint8_t *) &fifoCtrl))
2314   {
2315     return WE_FAIL;
2316   }
2317 
2318   *fifoThreshold = fifoCtrl.fifoThresholdLevel;
2319 
2320   return WE_SUCCESS;
2321 }
2322 
2323 /**
2324  * @brief Set the FIFO mode
2325  * @param[in] sensorInterface Pointer to sensor interface
2326  * @param[in] fifoMode FIFO mode
2327  * @retval Error code
2328  */
ITDS_setFifoMode(WE_sensorInterface_t * sensorInterface,ITDS_FifoMode_t fifoMode)2329 int8_t ITDS_setFifoMode(WE_sensorInterface_t* sensorInterface, ITDS_FifoMode_t fifoMode)
2330 {
2331   ITDS_fifoCtrl_t fifoCtrl;
2332 
2333   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_FIFO_CTRL_REG, 1, (uint8_t *) &fifoCtrl))
2334   {
2335     return WE_FAIL;
2336   }
2337 
2338   fifoCtrl.fifoMode = fifoMode;
2339 
2340   return ITDS_WriteReg(sensorInterface, ITDS_FIFO_CTRL_REG, 1, (uint8_t *) &fifoCtrl);
2341 }
2342 
2343 /**
2344  * @brief Read the FIFO mode
2345  * @param[in] sensorInterface Pointer to sensor interface
2346  * @param[out] fifoMode The returned FIFO mode
2347  * @retval Error code
2348  */
ITDS_getFifoMode(WE_sensorInterface_t * sensorInterface,ITDS_FifoMode_t * fifoMode)2349 int8_t ITDS_getFifoMode(WE_sensorInterface_t* sensorInterface, ITDS_FifoMode_t *fifoMode)
2350 {
2351   ITDS_fifoCtrl_t fifoCtrl;
2352 
2353   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_FIFO_CTRL_REG, 1, (uint8_t *) &fifoCtrl))
2354   {
2355     return WE_FAIL;
2356   }
2357 
2358   *fifoMode = (ITDS_FifoMode_t) fifoCtrl.fifoMode;
2359 
2360   return WE_SUCCESS;
2361 }
2362 
2363 
2364 /* FIFO_SAMPLES (0x2F) */
2365 
2366 /**
2367  * @brief Read the FIFO samples status
2368  * @param[in] sensorInterface Pointer to sensor interface
2369  * @param[out] fifoSamplesStatus The returned FIFO samples status
2370  * @retval Error code
2371  */
ITDS_getFifoSamplesRegister(WE_sensorInterface_t * sensorInterface,ITDS_fifoSamples_t * fifoSamplesStatus)2372 int8_t ITDS_getFifoSamplesRegister(WE_sensorInterface_t* sensorInterface, ITDS_fifoSamples_t *fifoSamplesStatus)
2373 {
2374   return ITDS_ReadReg(sensorInterface, ITDS_FIFO_SAMPLES_REG, 1, (uint8_t *) fifoSamplesStatus);
2375 }
2376 
2377 /**
2378  * @brief Read the FIFO threshold state [FIFO filling is lower than threshold level /
2379  * FIFO filling is equal to or higher than the threshold level]
2380  *
2381  * @param[in] sensorInterface Pointer to sensor interface
2382  * @param[out] fifoThr The returned FIFO threshold state
2383  * @retval Error code
2384  */
ITDS_isFifoThresholdReached(WE_sensorInterface_t * sensorInterface,ITDS_state_t * fifoThr)2385 int8_t ITDS_isFifoThresholdReached(WE_sensorInterface_t* sensorInterface, ITDS_state_t *fifoThr)
2386 {
2387   ITDS_fifoSamples_t fifoSamples;
2388 
2389   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_FIFO_SAMPLES_REG, 1, (uint8_t *) &fifoSamples))
2390   {
2391     return WE_FAIL;
2392   }
2393 
2394   *fifoThr = (ITDS_state_t) fifoSamples.fifoThresholdState;
2395 
2396   return WE_SUCCESS;
2397 }
2398 
2399 /**
2400  * @brief Read the FIFO overrun state [FIFO is not completely filled /
2401  * FIFO completely filled and at least one sample has been overwritten]
2402  *
2403  * @param[in] sensorInterface Pointer to sensor interface
2404  * @param[out] fifoOverrun The returned FIFO overrun state.
2405  * @retval Error code
2406  */
ITDS_getFifoOverrunState(WE_sensorInterface_t * sensorInterface,ITDS_state_t * fifoOverrun)2407 int8_t ITDS_getFifoOverrunState(WE_sensorInterface_t* sensorInterface, ITDS_state_t *fifoOverrun)
2408 {
2409   ITDS_fifoSamples_t fifoSamples;
2410 
2411   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_FIFO_SAMPLES_REG, 1, (uint8_t *) &fifoSamples))
2412   {
2413     return WE_FAIL;
2414   }
2415 
2416   *fifoOverrun = (ITDS_state_t) fifoSamples.fifoOverrunState;
2417 
2418   return WE_SUCCESS;
2419 }
2420 
2421 /**
2422  * @brief Read the FIFO fill level
2423  * @param[in] sensorInterface Pointer to sensor interface
2424  * @param[out] fifoFill The returned FIFO fill level (0-32)
2425  * @retval Error code
2426  */
ITDS_getFifoFillLevel(WE_sensorInterface_t * sensorInterface,uint8_t * fifoFill)2427 int8_t ITDS_getFifoFillLevel(WE_sensorInterface_t* sensorInterface, uint8_t *fifoFill)
2428 {
2429   ITDS_fifoSamples_t fifoSamples;
2430 
2431   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_FIFO_SAMPLES_REG, 1, (uint8_t *) &fifoSamples))
2432   {
2433     return WE_FAIL;
2434   }
2435 
2436   *fifoFill = fifoSamples.fifoFillLevel;
2437 
2438   return WE_SUCCESS;
2439 }
2440 
2441 
2442 /* TAP_X_TH (0x30) */
2443 
2444 /**
2445  * @brief Enable/disable 4D orientation detection
2446  * @param[in] sensorInterface Pointer to sensor interface
2447  * @param[in] detection4D The 4D orientation detection enable state
2448  * @retval Error code
2449  */
ITDS_enable4DDetection(WE_sensorInterface_t * sensorInterface,ITDS_state_t detection4D)2450 int8_t ITDS_enable4DDetection(WE_sensorInterface_t* sensorInterface, ITDS_state_t detection4D)
2451 {
2452   ITDS_tapXThreshold_t tapXThresh;
2453 
2454   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_X_TH_REG, 1, (uint8_t *) &tapXThresh))
2455   {
2456     return WE_FAIL;
2457   }
2458 
2459   tapXThresh.fourDDetectionEnabled = detection4D;
2460 
2461   return ITDS_WriteReg(sensorInterface, ITDS_TAP_X_TH_REG, 1, (uint8_t *) &tapXThresh);
2462 }
2463 
2464 /**
2465  * @brief Check if 4D orientation detection is enabled
2466  * @param[in] sensorInterface Pointer to sensor interface
2467  * @param[out] detection4D The returned 4D orientation detection enable state.
2468  * @retval Error code
2469  */
ITDS_is4DDetectionEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * detection4D)2470 int8_t ITDS_is4DDetectionEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *detection4D)
2471 {
2472   ITDS_tapXThreshold_t tapXThresh;
2473 
2474   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_X_TH_REG, 1, (uint8_t *) &tapXThresh))
2475   {
2476     return WE_FAIL;
2477   }
2478 
2479   *detection4D = (ITDS_state_t) tapXThresh.fourDDetectionEnabled;
2480 
2481   return WE_SUCCESS;
2482 }
2483 
2484 /**
2485  * @brief Set the tap threshold for axis X
2486  * @param[in] sensorInterface Pointer to sensor interface
2487  * @param[in] tapThresholdX Tap threshold for axis X (5 bits)
2488  * @retval Error code
2489  */
ITDS_setTapThresholdX(WE_sensorInterface_t * sensorInterface,uint8_t tapThresholdX)2490 int8_t ITDS_setTapThresholdX(WE_sensorInterface_t* sensorInterface, uint8_t tapThresholdX)
2491 {
2492   ITDS_tapXThreshold_t tapXThresh;
2493 
2494   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_X_TH_REG, 1, (uint8_t *) &tapXThresh))
2495   {
2496     return WE_FAIL;
2497   }
2498 
2499   tapXThresh.xAxisTapThreshold = tapThresholdX;
2500 
2501   return ITDS_WriteReg(sensorInterface, ITDS_TAP_X_TH_REG, 1, (uint8_t *) &tapXThresh);
2502 }
2503 
2504 /**
2505  * @brief Read the tap threshold for axis X
2506  * @param[in] sensorInterface Pointer to sensor interface
2507  * @param[out] tapThresholdX The returned tap threshold for axis X
2508  * @retval Error code
2509  */
ITDS_getTapThresholdX(WE_sensorInterface_t * sensorInterface,uint8_t * tapThresholdX)2510 int8_t ITDS_getTapThresholdX(WE_sensorInterface_t* sensorInterface, uint8_t *tapThresholdX)
2511 {
2512   ITDS_tapXThreshold_t tapXThresh;
2513 
2514   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_X_TH_REG, 1, (uint8_t *) &tapXThresh))
2515   {
2516     return WE_FAIL;
2517   }
2518 
2519   *tapThresholdX = tapXThresh.xAxisTapThreshold;
2520 
2521   return WE_SUCCESS;
2522 }
2523 
2524 /**
2525  * @brief Set the 6D orientation detection threshold (degrees)
2526  * @param[in] sensorInterface Pointer to sensor interface
2527  * @param[in] threshold6D 6D orientation detection threshold
2528  * @retval Error code
2529  */
ITDS_set6DThreshold(WE_sensorInterface_t * sensorInterface,ITDS_thresholdDegree_t threshold6D)2530 int8_t ITDS_set6DThreshold(WE_sensorInterface_t* sensorInterface, ITDS_thresholdDegree_t threshold6D)
2531 {
2532   ITDS_tapXThreshold_t tapXThresh;
2533 
2534   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_X_TH_REG, 1, (uint8_t *) &tapXThresh))
2535   {
2536     return WE_FAIL;
2537   }
2538 
2539   tapXThresh.sixDThreshold = threshold6D;
2540 
2541   return ITDS_WriteReg(sensorInterface, ITDS_TAP_X_TH_REG, 1, (uint8_t *) &tapXThresh);
2542 }
2543 
2544 /**
2545  * @brief Read the 6D orientation detection threshold (degrees)
2546  * @param[in] sensorInterface Pointer to sensor interface
2547  * @param[out] threshold6D The returned 6D orientation detection threshold
2548  * @retval Error code
2549  */
ITDS_get6DThreshold(WE_sensorInterface_t * sensorInterface,ITDS_thresholdDegree_t * threshold6D)2550 int8_t ITDS_get6DThreshold(WE_sensorInterface_t* sensorInterface, ITDS_thresholdDegree_t *threshold6D)
2551 {
2552   ITDS_tapXThreshold_t tapXThresh;
2553 
2554   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_X_TH_REG, 1, (uint8_t *) &tapXThresh))
2555   {
2556     return WE_FAIL;
2557   }
2558 
2559   *threshold6D = (ITDS_thresholdDegree_t) tapXThresh.sixDThreshold;
2560 
2561   return WE_SUCCESS;
2562 }
2563 
2564 
2565 /* TAP_Y_TH (0x31) */
2566 
2567 /**
2568  * @brief Set the tap threshold for axis Y
2569  * @param[in] sensorInterface Pointer to sensor interface
2570  * @param[in] tapThresholdY Tap threshold for axis Y (5 bits)
2571  * @retval Error code
2572  */
ITDS_setTapThresholdY(WE_sensorInterface_t * sensorInterface,uint8_t tapThresholdY)2573 int8_t ITDS_setTapThresholdY(WE_sensorInterface_t* sensorInterface, uint8_t tapThresholdY)
2574 {
2575   ITDS_tapYThreshold_t tapYThresh;
2576 
2577   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_Y_TH_REG, 1, (uint8_t *) &tapYThresh))
2578   {
2579     return WE_FAIL;
2580   }
2581 
2582   tapYThresh.yAxisTapThreshold = tapThresholdY;
2583 
2584   return ITDS_WriteReg(sensorInterface, ITDS_TAP_Y_TH_REG, 1, (uint8_t *) &tapYThresh);
2585 }
2586 
2587 /**
2588  * @brief Read the tap threshold for axis Y
2589  * @param[in] sensorInterface Pointer to sensor interface
2590  * @param[out] tapThresholdY The returned tap threshold for axis Y.
2591  * @retval Error code
2592  */
ITDS_getTapThresholdY(WE_sensorInterface_t * sensorInterface,uint8_t * tapThresholdY)2593 int8_t ITDS_getTapThresholdY(WE_sensorInterface_t* sensorInterface, uint8_t *tapThresholdY)
2594 {
2595   ITDS_tapYThreshold_t tapYThresh;
2596 
2597   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_Y_TH_REG, 1, (uint8_t *) &tapYThresh))
2598   {
2599     return WE_FAIL;
2600   }
2601 
2602   *tapThresholdY = tapYThresh.yAxisTapThreshold;
2603   return WE_SUCCESS;
2604 }
2605 
2606 /**
2607  * @brief Set the axis tap detection priority
2608  * @param[in] sensorInterface Pointer to sensor interface
2609  * @param[in] priority Axis tap detection priority
2610  * @retval Error code
2611  */
ITDS_setTapAxisPriority(WE_sensorInterface_t * sensorInterface,ITDS_tapAxisPriority_t priority)2612 int8_t ITDS_setTapAxisPriority(WE_sensorInterface_t* sensorInterface, ITDS_tapAxisPriority_t priority)
2613 {
2614   ITDS_tapYThreshold_t tapYThresh;
2615 
2616   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_Y_TH_REG, 1, (uint8_t *) &tapYThresh))
2617   {
2618     return WE_FAIL;
2619   }
2620 
2621   tapYThresh.tapAxisPriority = priority;
2622 
2623   return ITDS_WriteReg(sensorInterface, ITDS_TAP_Y_TH_REG, 1, (uint8_t *) &tapYThresh);
2624 }
2625 
2626 /**
2627  * @brief Read the axis tap detection priority
2628  * @param[in] sensorInterface Pointer to sensor interface
2629  * @param[out] priority The returned axis tap detection priority
2630  * @retval Error code
2631  */
ITDS_getTapAxisPriority(WE_sensorInterface_t * sensorInterface,ITDS_tapAxisPriority_t * priority)2632 int8_t ITDS_getTapAxisPriority(WE_sensorInterface_t* sensorInterface, ITDS_tapAxisPriority_t *priority)
2633 {
2634   ITDS_tapYThreshold_t tapYThresh;
2635 
2636   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_Y_TH_REG, 1, (uint8_t *) &tapYThresh))
2637   {
2638     return WE_FAIL;
2639   }
2640 
2641   *priority = (ITDS_tapAxisPriority_t) tapYThresh.tapAxisPriority;
2642 
2643   return WE_SUCCESS;
2644 }
2645 
2646 
2647 /* TAP_Z_TH (0x32) */
2648 
2649 /**
2650  * @brief Set the tap threshold for axis Z
2651  * @param[in] sensorInterface Pointer to sensor interface
2652  * @param[in] tapThresholdZ Tap threshold for axis Z (5 bits)
2653  * @retval Error code
2654  */
ITDS_setTapThresholdZ(WE_sensorInterface_t * sensorInterface,uint8_t tapThresholdZ)2655 int8_t ITDS_setTapThresholdZ(WE_sensorInterface_t* sensorInterface, uint8_t tapThresholdZ)
2656 {
2657   ITDS_tapZThreshold_t tapZThresh;
2658 
2659   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_Z_TH_REG, 1, (uint8_t *) &tapZThresh))
2660   {
2661     return WE_FAIL;
2662   }
2663 
2664   tapZThresh.zAxisTapThreshold = tapThresholdZ;
2665 
2666   return ITDS_WriteReg(sensorInterface, ITDS_TAP_Z_TH_REG, 1, (uint8_t *) &tapZThresh);
2667 }
2668 
2669 /**
2670  * @brief Read the tap threshold for axis Z
2671  * @param[in] sensorInterface Pointer to sensor interface
2672  * @param[out] tapThresholdZ The returned tap threshold for axis Z.
2673  * @retval Error code
2674  */
ITDS_getTapThresholdZ(WE_sensorInterface_t * sensorInterface,uint8_t * tapThresholdZ)2675 int8_t ITDS_getTapThresholdZ(WE_sensorInterface_t* sensorInterface, uint8_t *tapThresholdZ)
2676 {
2677   ITDS_tapZThreshold_t tapZThresh;
2678 
2679   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_Z_TH_REG, 1, (uint8_t *) &tapZThresh))
2680   {
2681     return WE_FAIL;
2682   }
2683 
2684   *tapThresholdZ = tapZThresh.zAxisTapThreshold;
2685 
2686   return WE_SUCCESS;
2687 }
2688 
2689 /**
2690  * @brief Enable/disable tap recognition in X direction
2691  * @param[in] sensorInterface Pointer to sensor interface
2692  * @param[in] tapX Tap X direction state
2693  * @retval Error code
2694  */
ITDS_enableTapX(WE_sensorInterface_t * sensorInterface,ITDS_state_t tapX)2695 int8_t ITDS_enableTapX(WE_sensorInterface_t* sensorInterface, ITDS_state_t tapX)
2696 {
2697   ITDS_tapZThreshold_t tapZThresh;
2698 
2699   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_Z_TH_REG, 1, (uint8_t *) &tapZThresh))
2700   {
2701     return WE_FAIL;
2702   }
2703 
2704   tapZThresh.enTapX = tapX;
2705 
2706   return ITDS_WriteReg(sensorInterface, ITDS_TAP_Z_TH_REG, 1, (uint8_t *) &tapZThresh);
2707 }
2708 
2709 /**
2710  * @brief Check if detection of tap events in X direction is enabled
2711  * @param[in] sensorInterface Pointer to sensor interface
2712  * @param[out] tapX The returned tap X direction state
2713  * @retval Error code
2714  */
ITDS_isTapXEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * tapX)2715 int8_t ITDS_isTapXEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *tapX)
2716 {
2717   ITDS_tapZThreshold_t tapZThresh;
2718 
2719   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_Z_TH_REG, 1, (uint8_t *) &tapZThresh))
2720   {
2721     return WE_FAIL;
2722   }
2723 
2724   *tapX = (ITDS_state_t) tapZThresh.enTapX;
2725 
2726   return WE_SUCCESS;
2727 }
2728 
2729 /**
2730  * @brief Enable/disable tap recognition in Y direction
2731  * @param[in] sensorInterface Pointer to sensor interface
2732  * @param[in] tapY Tap Y direction state
2733  * @retval Error code
2734  */
ITDS_enableTapY(WE_sensorInterface_t * sensorInterface,ITDS_state_t tapY)2735 int8_t ITDS_enableTapY(WE_sensorInterface_t* sensorInterface, ITDS_state_t tapY)
2736 {
2737   ITDS_tapZThreshold_t tapZThresh;
2738 
2739   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_Z_TH_REG, 1, (uint8_t *) &tapZThresh))
2740   {
2741     return WE_FAIL;
2742   }
2743 
2744   tapZThresh.enTapY = tapY;
2745 
2746   return ITDS_WriteReg(sensorInterface, ITDS_TAP_Z_TH_REG, 1, (uint8_t *) &tapZThresh);
2747 }
2748 
2749 /**
2750  * @brief Check if detection of tap events in Y direction is enabled
2751  * @param[in] sensorInterface Pointer to sensor interface
2752  * @param[out] tapY The returned tap Y direction state
2753  * @retval Error code
2754  */
ITDS_isTapYEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * tapY)2755 int8_t ITDS_isTapYEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *tapY)
2756 {
2757   ITDS_tapZThreshold_t tapZThresh;
2758 
2759   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_Z_TH_REG, 1, (uint8_t *) &tapZThresh))
2760   {
2761     return WE_FAIL;
2762   }
2763 
2764   *tapY = (ITDS_state_t) tapZThresh.enTapY;
2765 
2766   return WE_SUCCESS;
2767 }
2768 
2769 /**
2770  * @brief Enable/disable tap recognition in Z direction
2771  * @param[in] sensorInterface Pointer to sensor interface
2772  * @param[in] tapZ Tap Z direction state
2773  * @retval Error code
2774  */
ITDS_enableTapZ(WE_sensorInterface_t * sensorInterface,ITDS_state_t tapZ)2775 int8_t ITDS_enableTapZ(WE_sensorInterface_t* sensorInterface, ITDS_state_t tapZ)
2776 {
2777   ITDS_tapZThreshold_t tapZThresh;
2778 
2779   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_Z_TH_REG, 1, (uint8_t *) &tapZThresh))
2780   {
2781     return WE_FAIL;
2782   }
2783 
2784   tapZThresh.enTapZ = tapZ;
2785 
2786   return ITDS_WriteReg(sensorInterface, ITDS_TAP_Z_TH_REG, 1, (uint8_t *) &tapZThresh);
2787 }
2788 
2789 /**
2790  * @brief Check if detection of tap events in Z direction is enabled
2791  * @param[in] sensorInterface Pointer to sensor interface
2792  * @param[out] tapZ The returned tap Z direction state
2793  * @retval Error code
2794  */
ITDS_isTapZEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * tapZ)2795 int8_t ITDS_isTapZEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *tapZ)
2796 {
2797   ITDS_tapZThreshold_t tapZThresh;
2798 
2799   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_Z_TH_REG, 1, (uint8_t *) &tapZThresh))
2800   {
2801     return WE_FAIL;
2802   }
2803 
2804   *tapZ = (ITDS_state_t) tapZThresh.enTapZ;
2805 
2806   return WE_SUCCESS;
2807 }
2808 
2809 
2810 /* INT_DUR (0x33) */
2811 
2812 /**
2813  * @brief Set the maximum duration time gap for double-tap recognition (LATENCY)
2814  * @param[in] sensorInterface Pointer to sensor interface
2815  * @param[in] latencyTime Latency value (4 bits)
2816  * @retval Error code
2817  */
ITDS_setTapLatencyTime(WE_sensorInterface_t * sensorInterface,uint8_t latencyTime)2818 int8_t ITDS_setTapLatencyTime(WE_sensorInterface_t* sensorInterface, uint8_t latencyTime)
2819 {
2820   ITDS_intDuration_t intDuration;
2821 
2822   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_INT_DUR_REG, 1, (uint8_t *) &intDuration))
2823   {
2824     return WE_FAIL;
2825   }
2826 
2827   intDuration.latency = latencyTime;
2828 
2829   return ITDS_WriteReg(sensorInterface, ITDS_INT_DUR_REG, 1, (uint8_t *) &intDuration);
2830 }
2831 
2832 /**
2833  * @brief Read the maximum duration time gap for double-tap recognition (LATENCY)
2834  * @param[in] sensorInterface Pointer to sensor interface
2835  * @param[out] latencyTime The returned latency time
2836  * @retval Error code
2837  */
ITDS_getTapLatencyTime(WE_sensorInterface_t * sensorInterface,uint8_t * latencyTime)2838 int8_t ITDS_getTapLatencyTime(WE_sensorInterface_t* sensorInterface, uint8_t *latencyTime)
2839 {
2840   ITDS_intDuration_t intDuration;
2841 
2842   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_INT_DUR_REG, 1, (uint8_t *) &intDuration))
2843   {
2844     return WE_FAIL;
2845   }
2846 
2847   *latencyTime = intDuration.latency;
2848 
2849   return WE_SUCCESS;
2850 }
2851 
2852 /**
2853  * @brief Set the expected quiet time after a tap detection (QUIET)
2854  * @param[in] sensorInterface Pointer to sensor interface
2855  * @param[in] quietTime Quiet time value (2 bits)
2856  * @retval Error code
2857  */
ITDS_setTapQuietTime(WE_sensorInterface_t * sensorInterface,uint8_t quietTime)2858 int8_t ITDS_setTapQuietTime(WE_sensorInterface_t* sensorInterface, uint8_t quietTime)
2859 {
2860   ITDS_intDuration_t intDuration;
2861 
2862   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_INT_DUR_REG, 1, (uint8_t *) &intDuration))
2863   {
2864     return WE_FAIL;
2865   }
2866 
2867   intDuration.quiet = quietTime;
2868 
2869   return ITDS_WriteReg(sensorInterface, ITDS_INT_DUR_REG, 1, (uint8_t *) &intDuration);
2870 }
2871 
2872 /**
2873  * @brief Read the expected quiet time after a tap detection (QUIET)
2874  * @param[in] sensorInterface Pointer to sensor interface
2875  * @param[out] quietTime The returned quiet time
2876  * @retval Error code
2877  */
ITDS_getTapQuietTime(WE_sensorInterface_t * sensorInterface,uint8_t * quietTime)2878 int8_t ITDS_getTapQuietTime(WE_sensorInterface_t* sensorInterface, uint8_t *quietTime)
2879 {
2880 
2881   ITDS_intDuration_t intDuration;
2882 
2883   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_INT_DUR_REG, 1, (uint8_t *) &intDuration))
2884   {
2885     return WE_FAIL;
2886   }
2887 
2888   *quietTime = intDuration.quiet;
2889 
2890   return WE_SUCCESS;
2891 }
2892 
2893 /**
2894  * @brief Set the maximum duration of over-threshold events (SHOCK)
2895  * @param[in] sensorInterface Pointer to sensor interface
2896  * @param[in] shockTime Shock time value (2 bits)
2897  * @retval Error code
2898  */
ITDS_setTapShockTime(WE_sensorInterface_t * sensorInterface,uint8_t shockTime)2899 int8_t ITDS_setTapShockTime(WE_sensorInterface_t* sensorInterface, uint8_t shockTime)
2900 {
2901   ITDS_intDuration_t intDuration;
2902 
2903   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_INT_DUR_REG, 1, (uint8_t *) &intDuration))
2904   {
2905     return WE_FAIL;
2906   }
2907 
2908   intDuration.shock = shockTime;
2909 
2910   return ITDS_WriteReg(sensorInterface, ITDS_INT_DUR_REG, 1, (uint8_t *) &intDuration);
2911 }
2912 
2913 /**
2914  * @brief Read the maximum duration of over-threshold events (SHOCK)
2915  * @param[in] sensorInterface Pointer to sensor interface
2916  * @param[out] shockTime The returned shock time.
2917  * @retval Error code
2918  */
ITDS_getTapShockTime(WE_sensorInterface_t * sensorInterface,uint8_t * shockTime)2919 int8_t ITDS_getTapShockTime(WE_sensorInterface_t* sensorInterface, uint8_t *shockTime)
2920 {
2921   ITDS_intDuration_t intDuration;
2922 
2923   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_INT_DUR_REG, 1, (uint8_t *) &intDuration))
2924   {
2925     return WE_FAIL;
2926   }
2927 
2928   *shockTime = intDuration.shock;
2929 
2930   return WE_SUCCESS;
2931 }
2932 
2933 
2934 /* WAKE_UP_TH */
2935 
2936 /**
2937  * @brief Enable/disable the single and double-tap event OR only single-tap event
2938  * @param[in] sensorInterface Pointer to sensor interface
2939  * @param[in] doubleTap Tap event state [0: only single, 1: single and double-tap]
2940  * @retval Error code
2941  */
ITDS_enableDoubleTapEvent(WE_sensorInterface_t * sensorInterface,ITDS_state_t doubleTap)2942 int8_t ITDS_enableDoubleTapEvent(WE_sensorInterface_t* sensorInterface, ITDS_state_t doubleTap)
2943 {
2944   ITDS_wakeUpThreshold_t wakeUpThreshReg;
2945 
2946   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_TH_REG, 1, (uint8_t *) &wakeUpThreshReg))
2947   {
2948     return WE_FAIL;
2949   }
2950 
2951   wakeUpThreshReg.enDoubleTapEvent = doubleTap;
2952 
2953   return ITDS_WriteReg(sensorInterface, ITDS_WAKE_UP_TH_REG, 1, (uint8_t *) &wakeUpThreshReg);
2954 }
2955 
2956 /**
2957  * @brief Check if double-tap events are enabled
2958  * @param[in] sensorInterface Pointer to sensor interface
2959  * @param[out] doubleTap The returned tap event state [0: only single, 1: single and double-tap]
2960  * @retval Error code
2961  */
ITDS_isDoubleTapEventEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * doubleTap)2962 int8_t ITDS_isDoubleTapEventEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *doubleTap)
2963 {
2964   ITDS_wakeUpThreshold_t wakeUpThreshReg;
2965 
2966   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_TH_REG, 1, (uint8_t *) &wakeUpThreshReg))
2967   {
2968     return WE_FAIL;
2969   }
2970 
2971   *doubleTap = (ITDS_state_t) wakeUpThreshReg.enDoubleTapEvent;
2972 
2973   return WE_SUCCESS;
2974 }
2975 
2976 /**
2977  * @brief Enable/disable inactivity (sleep) detection
2978  * @param[in] sensorInterface Pointer to sensor interface
2979  * @param[in] inactivity Sleep detection enable state
2980  * @retval Error code
2981  */
ITDS_enableInactivityDetection(WE_sensorInterface_t * sensorInterface,ITDS_state_t inactivity)2982 int8_t ITDS_enableInactivityDetection(WE_sensorInterface_t* sensorInterface, ITDS_state_t inactivity)
2983 {
2984   ITDS_wakeUpThreshold_t wakeUpThreshReg;
2985 
2986   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_TH_REG, 1, (uint8_t *) &wakeUpThreshReg))
2987   {
2988     return WE_FAIL;
2989   }
2990 
2991   wakeUpThreshReg.enInactivityEvent = inactivity;
2992 
2993   return ITDS_WriteReg(sensorInterface, ITDS_WAKE_UP_TH_REG, 1, (uint8_t *) &wakeUpThreshReg);
2994 }
2995 
2996 /**
2997  * @brief Check if inactivity (sleep) detection is enabled
2998  * @param[in] sensorInterface Pointer to sensor interface
2999  * @param[out] inactivity The returned inactivity (sleep) detection enable state.
3000  * @retval Error code
3001  */
ITDS_isInactivityDetectionEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * inactivity)3002 int8_t ITDS_isInactivityDetectionEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *inactivity)
3003 {
3004   ITDS_wakeUpThreshold_t wakeUpThreshReg;
3005 
3006   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_TH_REG, 1, (uint8_t *) &wakeUpThreshReg))
3007   {
3008     return WE_FAIL;
3009   }
3010 
3011   *inactivity = (ITDS_state_t) wakeUpThreshReg.enInactivityEvent;
3012 
3013   return WE_SUCCESS;
3014 }
3015 
3016 /**
3017  * @brief Set wake-up threshold
3018  * @param[in] sensorInterface Pointer to sensor interface
3019  * @param[in] wakeUpThresh Wake-up threshold (six bits)
3020  * @retval Error code
3021  */
ITDS_setWakeUpThreshold(WE_sensorInterface_t * sensorInterface,uint8_t wakeUpThresh)3022 int8_t ITDS_setWakeUpThreshold(WE_sensorInterface_t* sensorInterface, uint8_t wakeUpThresh)
3023 {
3024   ITDS_wakeUpThreshold_t wakeUpThreshReg;
3025 
3026   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_TH_REG, 1, (uint8_t *) &wakeUpThreshReg))
3027   {
3028     return WE_FAIL;
3029   }
3030 
3031   wakeUpThreshReg.wakeUpThreshold = wakeUpThresh;
3032 
3033   return ITDS_WriteReg(sensorInterface, ITDS_WAKE_UP_TH_REG, 1, (uint8_t *) &wakeUpThreshReg);
3034 }
3035 
3036 /**
3037  * @brief Read the wake-up threshold
3038  * @param[in] sensorInterface Pointer to sensor interface
3039  * @param[out] wakeUpThresh The returned wake-up threshold.
3040  * @retval Error code
3041  */
ITDS_getWakeUpThreshold(WE_sensorInterface_t * sensorInterface,uint8_t * wakeUpThresh)3042 int8_t ITDS_getWakeUpThreshold(WE_sensorInterface_t* sensorInterface, uint8_t *wakeUpThresh)
3043 {
3044   ITDS_wakeUpThreshold_t wakeUpThreshReg;
3045 
3046   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_TH_REG, 1, (uint8_t *) &wakeUpThreshReg))
3047   {
3048     return WE_FAIL;
3049   }
3050 
3051   *wakeUpThresh = wakeUpThreshReg.wakeUpThreshold;
3052 
3053   return WE_SUCCESS;
3054 }
3055 
3056 
3057 /* WAKE_UP_DUR */
3058 
3059 /**
3060  * @brief Set free-fall duration MSB
3061  * @param[in] sensorInterface Pointer to sensor interface
3062  * @param[in] freeFallDurationMsb Free-fall duration MSB
3063  * @retval Error code
3064  */
ITDS_setFreeFallDurationMSB(WE_sensorInterface_t * sensorInterface,uint8_t freeFallDurationMsb)3065 int8_t ITDS_setFreeFallDurationMSB(WE_sensorInterface_t* sensorInterface, uint8_t freeFallDurationMsb)
3066 {
3067   ITDS_wakeUpDuration_t wakeUpDuration;
3068 
3069   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_DUR_REG, 1, (uint8_t *) &wakeUpDuration))
3070   {
3071     return WE_FAIL;
3072   }
3073 
3074   wakeUpDuration.freeFallDurationMSB = freeFallDurationMsb;
3075 
3076   return ITDS_WriteReg(sensorInterface, ITDS_WAKE_UP_DUR_REG, 1, (uint8_t *) &wakeUpDuration);
3077 }
3078 
3079 /**
3080  * @brief Read the free-fall duration MSB
3081  * @param[in] sensorInterface Pointer to sensor interface
3082  * @param[out] freeFallDurationMsb The returned free-fall duration MSB
3083  * @retval Error code
3084  */
ITDS_getFreeFallDurationMSB(WE_sensorInterface_t * sensorInterface,uint8_t * freeFallDurationMsb)3085 int8_t ITDS_getFreeFallDurationMSB(WE_sensorInterface_t* sensorInterface, uint8_t *freeFallDurationMsb)
3086 {
3087   ITDS_wakeUpDuration_t wakeUpDuration;
3088 
3089   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_DUR_REG, 1, (uint8_t *) &wakeUpDuration))
3090   {
3091     return WE_FAIL;
3092   }
3093 
3094   *freeFallDurationMsb = wakeUpDuration.freeFallDurationMSB;
3095   return WE_SUCCESS;
3096 }
3097 
3098 /**
3099  * @brief Enable/disable stationary detection
3100  * @param[in] sensorInterface Pointer to sensor interface
3101  * @param[in] stationary Stationary detection enable state
3102  * @retval Error code
3103  */
ITDS_enableStationaryDetection(WE_sensorInterface_t * sensorInterface,ITDS_state_t stationary)3104 int8_t ITDS_enableStationaryDetection(WE_sensorInterface_t* sensorInterface, ITDS_state_t stationary)
3105 {
3106   ITDS_wakeUpDuration_t wakeUpDuration;
3107 
3108   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_DUR_REG, 1, (uint8_t *) &wakeUpDuration))
3109   {
3110     return WE_FAIL;
3111   }
3112 
3113   wakeUpDuration.enStationary = stationary;
3114 
3115   return ITDS_WriteReg(sensorInterface, ITDS_WAKE_UP_DUR_REG, 1, (uint8_t *) &wakeUpDuration);
3116 }
3117 
3118 /**
3119  * @brief Check if stationary detection is enabled
3120  * @param[in] sensorInterface Pointer to sensor interface
3121  * @param[out] stationary The returned stationary detection enable state
3122  * @retval Error code
3123  */
ITDS_isStationaryDetectionEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * stationary)3124 int8_t ITDS_isStationaryDetectionEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *stationary)
3125 {
3126   ITDS_wakeUpDuration_t wakeUpDuration;
3127 
3128   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_DUR_REG, 1, (uint8_t *) &wakeUpDuration))
3129   {
3130     return WE_FAIL;
3131   }
3132 
3133   *stationary = (ITDS_state_t) wakeUpDuration.enStationary;
3134 
3135   return WE_SUCCESS;
3136 }
3137 
3138 /**
3139  * @brief Set wake-up duration
3140  * @param[in] sensorInterface Pointer to sensor interface
3141  * @param[in] duration Wake-up duration (two bits)
3142  * @retval Error code
3143  */
ITDS_setWakeUpDuration(WE_sensorInterface_t * sensorInterface,uint8_t duration)3144 int8_t ITDS_setWakeUpDuration(WE_sensorInterface_t* sensorInterface, uint8_t duration)
3145 {
3146   ITDS_wakeUpDuration_t wakeUpDuration;
3147 
3148   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_DUR_REG, 1, (uint8_t *) &wakeUpDuration))
3149   {
3150     return WE_FAIL;
3151   }
3152 
3153   wakeUpDuration.wakeUpDuration = duration;
3154 
3155   return ITDS_WriteReg(sensorInterface, ITDS_WAKE_UP_DUR_REG, 1, (uint8_t *) &wakeUpDuration);
3156 }
3157 
3158 /**
3159  * @brief Read the wake-up duration
3160  * @param[in] sensorInterface Pointer to sensor interface
3161  * @param[out] duration The returned wake-up duration (two bits)
3162  * @retval Error code
3163  */
ITDS_getWakeUpDuration(WE_sensorInterface_t * sensorInterface,uint8_t * duration)3164 int8_t ITDS_getWakeUpDuration(WE_sensorInterface_t* sensorInterface, uint8_t *duration)
3165 {
3166   ITDS_wakeUpDuration_t wakeUpDuration;
3167 
3168   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_DUR_REG, 1, (uint8_t *) &wakeUpDuration))
3169   {
3170     return WE_FAIL;
3171   }
3172 
3173   *duration = wakeUpDuration.wakeUpDuration;
3174 
3175   return WE_SUCCESS;
3176 }
3177 
3178 /**
3179  * @brief Set the sleep mode duration
3180  * @param[in] sensorInterface Pointer to sensor interface
3181  * @param[in] duration Sleep mode duration (4 bits)
3182  * @retval Error code
3183  */
ITDS_setSleepDuration(WE_sensorInterface_t * sensorInterface,uint8_t duration)3184 int8_t ITDS_setSleepDuration(WE_sensorInterface_t* sensorInterface, uint8_t duration)
3185 {
3186   ITDS_wakeUpDuration_t wakeUpDuration;
3187 
3188   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_DUR_REG, 1, (uint8_t *) &wakeUpDuration))
3189   {
3190     return WE_FAIL;
3191   }
3192 
3193   wakeUpDuration.sleepDuration = duration;
3194 
3195   return ITDS_WriteReg(sensorInterface, ITDS_WAKE_UP_DUR_REG, 1, (uint8_t *) &wakeUpDuration);
3196 }
3197 
3198 /**
3199  * @brief Read the sleep mode duration
3200  * @param[in] sensorInterface Pointer to sensor interface
3201  * @param[out] duration The returned sleep mode duration
3202  * @retval Error code
3203  */
ITDS_getSleepDuration(WE_sensorInterface_t * sensorInterface,uint8_t * duration)3204 int8_t ITDS_getSleepDuration(WE_sensorInterface_t* sensorInterface, uint8_t *duration)
3205 {
3206   ITDS_wakeUpDuration_t wakeUpDuration;
3207 
3208   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_DUR_REG, 1, (uint8_t *) &wakeUpDuration))
3209   {
3210     return WE_FAIL;
3211   }
3212 
3213   *duration = wakeUpDuration.sleepDuration;
3214 
3215   return WE_SUCCESS;
3216 }
3217 
3218 
3219 /* FREE_FALL */
3220 
3221 /**
3222  * @brief Set the free-fall duration (both LSB and MSB).
3223  * @param[in] sensorInterface Pointer to sensor interface
3224  * @param[in] freeFallDuration Free-fall duration (6 bits)
3225  * @retval Error code
3226  */
ITDS_setFreeFallDuration(WE_sensorInterface_t * sensorInterface,uint8_t freeFallDuration)3227 int8_t ITDS_setFreeFallDuration(WE_sensorInterface_t* sensorInterface, uint8_t freeFallDuration)
3228 {
3229   /* Set first 5 bits as LSB, 6th bit as MSB */
3230   if (WE_FAIL == ITDS_setFreeFallDurationLSB(sensorInterface, freeFallDuration & 0x1F))
3231   {
3232     return WE_FAIL;
3233   }
3234   return ITDS_setFreeFallDurationMSB(sensorInterface, (freeFallDuration >> 5) & 0x1);
3235 }
3236 
3237 /**
3238  * @brief Read the free-fall duration (both LSB and MSB).
3239  * @param[in] sensorInterface Pointer to sensor interface
3240  * @param[out] freeFallDuration The returned free-fall duration (6 bits)
3241  * @retval Error code
3242  */
ITDS_getFreeFallDuration(WE_sensorInterface_t * sensorInterface,uint8_t * freeFallDuration)3243 int8_t ITDS_getFreeFallDuration(WE_sensorInterface_t* sensorInterface, uint8_t *freeFallDuration)
3244 {
3245   uint8_t lsb;
3246   uint8_t msb;
3247 
3248   if (WE_FAIL == ITDS_getFreeFallDurationLSB(sensorInterface, &lsb))
3249   {
3250     return WE_FAIL;
3251   }
3252   if (WE_FAIL == ITDS_getFreeFallDurationMSB(sensorInterface, &msb))
3253   {
3254     return WE_FAIL;
3255   }
3256 
3257   *freeFallDuration = (lsb & 0x1F) | ((msb & 0x1) << 5);
3258 
3259   return WE_SUCCESS;
3260 }
3261 
3262 /**
3263  * @brief Set free-fall duration LSB
3264  * @param[in] sensorInterface Pointer to sensor interface
3265  * @param[in] freeFallDurationLsb Free-fall duration LSB (5 bits)
3266  * @retval Error code
3267  */
ITDS_setFreeFallDurationLSB(WE_sensorInterface_t * sensorInterface,uint8_t freeFallDurationLsb)3268 int8_t ITDS_setFreeFallDurationLSB(WE_sensorInterface_t* sensorInterface, uint8_t freeFallDurationLsb)
3269 {
3270   ITDS_freeFall_t freeFall;
3271 
3272   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_FREE_FALL_REG, 1, (uint8_t *) &freeFall))
3273   {
3274     return WE_FAIL;
3275   }
3276 
3277   freeFall.freeFallDurationLSB = freeFallDurationLsb;
3278 
3279   return ITDS_WriteReg(sensorInterface, ITDS_FREE_FALL_REG, 1, (uint8_t *) &freeFall);
3280 }
3281 
3282 /**
3283  * @brief Read the free-fall duration LSB
3284  * @param[in] sensorInterface Pointer to sensor interface
3285  * @param[out] freeFallDurationLsb The returned free-fall duration LSB (5 bits)
3286  * @retval Error code
3287  */
ITDS_getFreeFallDurationLSB(WE_sensorInterface_t * sensorInterface,uint8_t * freeFallDurationLsb)3288 int8_t ITDS_getFreeFallDurationLSB(WE_sensorInterface_t* sensorInterface, uint8_t *freeFallDurationLsb)
3289 {
3290   ITDS_freeFall_t freeFall;
3291 
3292   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_FREE_FALL_REG, 1, (uint8_t *) &freeFall))
3293   {
3294     return WE_FAIL;
3295   }
3296 
3297   *freeFallDurationLsb = freeFall.freeFallDurationLSB;
3298   return WE_SUCCESS;
3299 }
3300 
3301 /**
3302  * @brief Set free-fall threshold
3303  * @param[in] sensorInterface Pointer to sensor interface
3304  * @param[in] threshold Encoded free-fall threshold value (3 bits)
3305  * @retval Error code
3306  */
ITDS_setFreeFallThreshold(WE_sensorInterface_t * sensorInterface,ITDS_FreeFallThreshold_t threshold)3307 int8_t ITDS_setFreeFallThreshold(WE_sensorInterface_t* sensorInterface, ITDS_FreeFallThreshold_t threshold)
3308 {
3309   ITDS_freeFall_t freeFall;
3310 
3311   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_FREE_FALL_REG, 1, (uint8_t *) &freeFall))
3312   {
3313     return WE_FAIL;
3314   }
3315 
3316   freeFall.freeFallThreshold = threshold;
3317 
3318   return ITDS_WriteReg(sensorInterface, ITDS_FREE_FALL_REG, 1, (uint8_t *) &freeFall);
3319 }
3320 
3321 /**
3322  * @brief Read the free-fall threshold
3323  * @param[in] sensorInterface Pointer to sensor interface
3324  * @param[out] threshold The returned encoded free-fall threshold value (3 bits)
3325  * @retval Error code
3326  */
ITDS_getFreeFallThreshold(WE_sensorInterface_t * sensorInterface,ITDS_FreeFallThreshold_t * threshold)3327 int8_t ITDS_getFreeFallThreshold(WE_sensorInterface_t* sensorInterface, ITDS_FreeFallThreshold_t *threshold)
3328 {
3329   ITDS_freeFall_t freeFall;
3330 
3331   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_FREE_FALL_REG, 1, (uint8_t *) &freeFall))
3332   {
3333     return WE_FAIL;
3334   }
3335 
3336   *threshold = (ITDS_FreeFallThreshold_t) freeFall.freeFallThreshold;
3337   return WE_SUCCESS;
3338 }
3339 
3340 
3341 /* STATUS_DETECT */
3342 /* Note: Most of the status bits are already covered by the STATUS_REG register. */
3343 
3344 /**
3345  * @brief Read the status detect register state
3346  * @param[in] sensorInterface Pointer to sensor interface
3347  * @param[out] statusDetect The returned status detect register state
3348  * @retval Error code
3349  */
ITDS_getStatusDetectRegister(WE_sensorInterface_t * sensorInterface,ITDS_statusDetect_t * statusDetect)3350 int8_t ITDS_getStatusDetectRegister(WE_sensorInterface_t* sensorInterface, ITDS_statusDetect_t *statusDetect)
3351 {
3352   return ITDS_ReadReg(sensorInterface, ITDS_STATUS_DETECT_REG, 1, (uint8_t *) statusDetect);
3353 }
3354 
3355 /**
3356  * @brief Check if new temperature samples are available.
3357  * @param[in] sensorInterface Pointer to sensor interface
3358  * @param[out] dataReady The returned data-ready state
3359  * @retval Error code
3360  */
ITDS_isTemperatureDataReady(WE_sensorInterface_t * sensorInterface,ITDS_state_t * dataReady)3361 int8_t ITDS_isTemperatureDataReady(WE_sensorInterface_t* sensorInterface, ITDS_state_t *dataReady)
3362 {
3363   ITDS_statusDetect_t statusDetect;
3364 
3365   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_STATUS_DETECT_REG, 1, (uint8_t *) &statusDetect))
3366   {
3367     return WE_FAIL;
3368   }
3369 
3370   *dataReady = (ITDS_state_t) statusDetect.temperatureDataReady;
3371   return WE_SUCCESS;
3372 }
3373 
3374 
3375 /* WAKE_UP_EVENT */
3376 
3377 /**
3378  * @brief Read the overall wake-up event status
3379  * @param[in] sensorInterface Pointer to sensor interface
3380  * @param[out] status The returned wake-up event status
3381  * @retval Error code
3382  */
ITDS_getWakeUpEventRegister(WE_sensorInterface_t * sensorInterface,ITDS_wakeUpEvent_t * status)3383 int8_t ITDS_getWakeUpEventRegister(WE_sensorInterface_t* sensorInterface, ITDS_wakeUpEvent_t *status)
3384 {
3385   return ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_EVENT_REG, 1, (uint8_t *) status);
3386 }
3387 
3388 /**
3389  * @brief Read the wake-up event detection status on axis X
3390  * @param[in] sensorInterface Pointer to sensor interface
3391  * @param[out] wakeUpX The returned wake-up event detection status on axis X.
3392  * @retval Error code
3393  */
ITDS_isWakeUpXEvent(WE_sensorInterface_t * sensorInterface,ITDS_state_t * wakeUpX)3394 int8_t ITDS_isWakeUpXEvent(WE_sensorInterface_t* sensorInterface, ITDS_state_t *wakeUpX)
3395 {
3396   ITDS_wakeUpEvent_t wakeUpEvent;
3397 
3398   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_EVENT_REG, 1, (uint8_t *) &wakeUpEvent))
3399   {
3400     return WE_FAIL;
3401   }
3402 
3403   *wakeUpX = (ITDS_state_t) wakeUpEvent.wakeUpX;
3404 
3405   return WE_SUCCESS;
3406 }
3407 
3408 /**
3409  * @brief Read the wake-up event detection status on axis Y
3410  * @param[in] sensorInterface Pointer to sensor interface
3411  * @param[out] wakeUpY The returned wake-up event detection status on axis Y.
3412  * @retval Error code
3413  */
ITDS_isWakeUpYEvent(WE_sensorInterface_t * sensorInterface,ITDS_state_t * wakeUpY)3414 int8_t ITDS_isWakeUpYEvent(WE_sensorInterface_t* sensorInterface, ITDS_state_t *wakeUpY)
3415 {
3416   ITDS_wakeUpEvent_t wakeUpEvent;
3417 
3418   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_EVENT_REG, 1, (uint8_t *) &wakeUpEvent))
3419   {
3420     return WE_FAIL;
3421   }
3422 
3423   *wakeUpY = (ITDS_state_t) wakeUpEvent.wakeUpY;
3424 
3425   return WE_SUCCESS;
3426 }
3427 
3428 /**
3429  * @brief Read the wake-up event detection status on axis Z
3430  * @param[in] sensorInterface Pointer to sensor interface
3431  * @param[out] wakeUpZ The returned wake-up event detection status on axis Z.
3432  * @retval Error code
3433  */
ITDS_isWakeUpZEvent(WE_sensorInterface_t * sensorInterface,ITDS_state_t * wakeUpZ)3434 int8_t ITDS_isWakeUpZEvent(WE_sensorInterface_t* sensorInterface, ITDS_state_t *wakeUpZ)
3435 {
3436   ITDS_wakeUpEvent_t wakeUpEvent;
3437 
3438   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_EVENT_REG, 1, (uint8_t *) &wakeUpEvent))
3439   {
3440     return WE_FAIL;
3441   }
3442 
3443   *wakeUpZ = (ITDS_state_t) wakeUpEvent.wakeUpZ;
3444 
3445   return WE_SUCCESS;
3446 }
3447 
3448 /**
3449  * @brief Read the wake-up event detection status (wake-up event on any axis)
3450  * @param[in] sensorInterface Pointer to sensor interface
3451  * @param[out] wakeUpState The returned wake-up event detection state.
3452  * @retval Error code
3453  */
ITDS_isWakeUpEvent(WE_sensorInterface_t * sensorInterface,ITDS_state_t * wakeUpState)3454 int8_t ITDS_isWakeUpEvent(WE_sensorInterface_t* sensorInterface, ITDS_state_t *wakeUpState)
3455 {
3456   ITDS_wakeUpEvent_t wakeUpEvent;
3457 
3458   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_EVENT_REG, 1, (uint8_t *) &wakeUpEvent))
3459   {
3460     return WE_FAIL;
3461   }
3462 
3463   *wakeUpState = (ITDS_state_t) wakeUpEvent.wakeUpState;
3464 
3465   return WE_SUCCESS;
3466 }
3467 
3468 /**
3469  * @brief Read the free-fall event state [not detected/detected]
3470  * @param[in] sensorInterface Pointer to sensor interface
3471  * @param[out] freeFall The returned free-fall event status.
3472  * @retval Error code
3473  */
ITDS_isFreeFallEvent(WE_sensorInterface_t * sensorInterface,ITDS_state_t * freeFall)3474 int8_t ITDS_isFreeFallEvent(WE_sensorInterface_t* sensorInterface, ITDS_state_t *freeFall)
3475 {
3476   ITDS_wakeUpEvent_t wakeUpEvent;
3477 
3478   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_WAKE_UP_EVENT_REG, 1, (uint8_t *) &wakeUpEvent))
3479   {
3480     return WE_FAIL;
3481   }
3482 
3483   *freeFall = (ITDS_state_t) wakeUpEvent.freeFallState;
3484 
3485   return WE_SUCCESS;
3486 }
3487 
3488 
3489 /* TAP EVENT 0x39 */
3490 
3491 /**
3492  * @brief Read the overall tap event status
3493  * @param[in] sensorInterface Pointer to sensor interface
3494  * @param[out] status The returned tap event status
3495  * @retval Error code
3496  */
ITDS_getTapEventRegister(WE_sensorInterface_t * sensorInterface,ITDS_tapEvent_t * status)3497 int8_t ITDS_getTapEventRegister(WE_sensorInterface_t* sensorInterface, ITDS_tapEvent_t *status)
3498 {
3499   return ITDS_ReadReg(sensorInterface, ITDS_TAP_EVENT_REG, 1, (uint8_t *) status);
3500 }
3501 
3502 /**
3503  * @brief Read the tap event status (tap event on any axis)
3504  * @param[in] sensorInterface Pointer to sensor interface
3505  * @param[out] tapEventState The returned tap event state
3506  * @retval Error code
3507  */
ITDS_isTapEvent(WE_sensorInterface_t * sensorInterface,ITDS_state_t * tapEventState)3508 int8_t ITDS_isTapEvent(WE_sensorInterface_t* sensorInterface, ITDS_state_t *tapEventState)
3509 {
3510   ITDS_tapEvent_t tapEvent;
3511 
3512   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_EVENT_REG, 1, (uint8_t *) &tapEvent))
3513   {
3514     return WE_FAIL;
3515   }
3516 
3517   *tapEventState = (ITDS_state_t) tapEvent.tapEventState;
3518 
3519   return WE_SUCCESS;
3520 }
3521 
3522 /**
3523  * @brief Read the tap event acceleration sign (direction of tap event)
3524  * @param[in] sensorInterface Pointer to sensor interface
3525  * @param[out] tapSign The returned tap event acceleration sign
3526  * @retval Error code
3527  */
ITDS_getTapSign(WE_sensorInterface_t * sensorInterface,ITDS_tapSign_t * tapSign)3528 int8_t ITDS_getTapSign(WE_sensorInterface_t* sensorInterface, ITDS_tapSign_t *tapSign)
3529 {
3530   ITDS_tapEvent_t tapEvent;
3531 
3532   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_EVENT_REG, 1, (uint8_t *) &tapEvent))
3533   {
3534     return WE_FAIL;
3535   }
3536 
3537   *tapSign = (ITDS_tapSign_t) tapEvent.tapSign;
3538 
3539   return WE_SUCCESS;
3540 }
3541 
3542 /**
3543  * @brief Read the tap event status on axis X
3544  * @param[in] sensorInterface Pointer to sensor interface
3545  * @param[out] tapXAxis The returned tap event status on axis X.
3546  * @retval Error code
3547  */
ITDS_isTapEventXAxis(WE_sensorInterface_t * sensorInterface,ITDS_state_t * tapXAxis)3548 int8_t ITDS_isTapEventXAxis(WE_sensorInterface_t* sensorInterface, ITDS_state_t *tapXAxis)
3549 {
3550   ITDS_tapEvent_t tapEvent;
3551 
3552   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_EVENT_REG, 1, (uint8_t *) &tapEvent))
3553   {
3554     return WE_FAIL;
3555   }
3556 
3557   *tapXAxis = (ITDS_state_t) tapEvent.tapXAxis;
3558 
3559   return WE_SUCCESS;
3560 }
3561 
3562 /**
3563  * @brief Read the tap event status on axis Y
3564  * @param[in] sensorInterface Pointer to sensor interface
3565  * @param[out] tapYAxis The returned tap event status on axis Y.
3566  * @retval Error code
3567  */
ITDS_isTapEventYAxis(WE_sensorInterface_t * sensorInterface,ITDS_state_t * tapYAxis)3568 int8_t ITDS_isTapEventYAxis(WE_sensorInterface_t* sensorInterface, ITDS_state_t *tapYAxis)
3569 {
3570   ITDS_tapEvent_t tapEvent;
3571 
3572   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_EVENT_REG, 1, (uint8_t *) &tapEvent))
3573   {
3574     return WE_FAIL;
3575   }
3576 
3577   *tapYAxis = (ITDS_state_t) tapEvent.tapYAxis;
3578 
3579   return WE_SUCCESS;
3580 }
3581 
3582 /**
3583  * @brief Read the tap event status on axis Z
3584  * @param[in] sensorInterface Pointer to sensor interface
3585  * @param[out] tapZAxis The returned tap event status on axis Z.
3586  * @retval Error code
3587  */
ITDS_isTapEventZAxis(WE_sensorInterface_t * sensorInterface,ITDS_state_t * tapZAxis)3588 int8_t ITDS_isTapEventZAxis(WE_sensorInterface_t* sensorInterface, ITDS_state_t *tapZAxis)
3589 {
3590   ITDS_tapEvent_t tapEvent;
3591 
3592   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_TAP_EVENT_REG, 1, (uint8_t *) &tapEvent))
3593   {
3594     return WE_FAIL;
3595   }
3596 
3597   *tapZAxis = (ITDS_state_t) tapEvent.tapZAxis;
3598 
3599   return WE_SUCCESS;
3600 }
3601 
3602 
3603 /* 6D_EVENT */
3604 
3605 /**
3606  * @brief Read register containing info on 6D orientation change event.
3607  * @param[in] sensorInterface Pointer to sensor interface
3608  * @param[out] status The returned 6D event status.
3609  * @retval Error code
3610  */
ITDS_get6dEventRegister(WE_sensorInterface_t * sensorInterface,ITDS_6dEvent_t * status)3611 int8_t ITDS_get6dEventRegister(WE_sensorInterface_t* sensorInterface, ITDS_6dEvent_t *status)
3612 {
3613   return ITDS_ReadReg(sensorInterface, ITDS_6D_EVENT_REG, 1, (uint8_t *) status);
3614 }
3615 
3616 /**
3617  * @brief Check if 6D orientation change event has occurred.
3618  * @param[in] sensorInterface Pointer to sensor interface
3619  * @param[out] orientationChanged The returned 6D orientation change event status
3620  * @retval Error code
3621  */
ITDS_has6dOrientationChanged(WE_sensorInterface_t * sensorInterface,ITDS_state_t * orientationChanged)3622 int8_t ITDS_has6dOrientationChanged(WE_sensorInterface_t* sensorInterface, ITDS_state_t *orientationChanged)
3623 {
3624   ITDS_6dEvent_t event6d;
3625 
3626   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_6D_EVENT_REG, 1, (uint8_t *) &event6d))
3627   {
3628     return WE_FAIL;
3629   }
3630 
3631   *orientationChanged = (ITDS_state_t) event6d.sixDChange;
3632 
3633   return WE_SUCCESS;
3634 }
3635 
3636 /**
3637  * @brief Read the XL over threshold state (6D orientation)
3638  * @param[in] sensorInterface Pointer to sensor interface
3639  * @param[out] xlOverThreshold The returned XL over threshold state
3640  * @retval Error code
3641  */
ITDS_isXLOverThreshold(WE_sensorInterface_t * sensorInterface,ITDS_state_t * xlOverThreshold)3642 int8_t ITDS_isXLOverThreshold(WE_sensorInterface_t* sensorInterface, ITDS_state_t *xlOverThreshold)
3643 {
3644   ITDS_6dEvent_t event6d;
3645 
3646   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_6D_EVENT_REG, 1, (uint8_t *) &event6d))
3647   {
3648     return WE_FAIL;
3649   }
3650 
3651   *xlOverThreshold = (ITDS_state_t) event6d.xlOverThreshold;
3652 
3653   return WE_SUCCESS;
3654 }
3655 
3656 /**
3657  * @brief Read the XH over threshold state (6D orientation)
3658  * @param[in] sensorInterface Pointer to sensor interface
3659  * @param[out] xhOverThreshold The returned XH over threshold state
3660  * @retval Error code
3661  */
ITDS_isXHOverThreshold(WE_sensorInterface_t * sensorInterface,ITDS_state_t * xhOverThreshold)3662 int8_t ITDS_isXHOverThreshold(WE_sensorInterface_t* sensorInterface, ITDS_state_t *xhOverThreshold)
3663 {
3664   ITDS_6dEvent_t event6d;
3665 
3666   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_6D_EVENT_REG, 1, (uint8_t *) &event6d))
3667   {
3668     return WE_FAIL;
3669   }
3670 
3671   *xhOverThreshold = (ITDS_state_t) event6d.xhOverThreshold;
3672 
3673   return WE_SUCCESS;
3674 }
3675 
3676 /**
3677  * @brief Read the YL over threshold state (6D orientation)
3678  * @param[in] sensorInterface Pointer to sensor interface
3679  * @param[out] ylOverThreshold The returned YL over threshold state
3680  * @retval Error code
3681  */
ITDS_isYLOverThreshold(WE_sensorInterface_t * sensorInterface,ITDS_state_t * ylOverThreshold)3682 int8_t ITDS_isYLOverThreshold(WE_sensorInterface_t* sensorInterface, ITDS_state_t *ylOverThreshold)
3683 {
3684   ITDS_6dEvent_t event6d;
3685 
3686   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_6D_EVENT_REG, 1, (uint8_t *) &event6d))
3687   {
3688     return WE_FAIL;
3689   }
3690 
3691   *ylOverThreshold = (ITDS_state_t) event6d.ylOverThreshold;
3692 
3693   return WE_SUCCESS;
3694 }
3695 
3696 /**
3697  * @brief Read the YH over threshold state (6D orientation)
3698  * @param[in] sensorInterface Pointer to sensor interface
3699  * @param[out] yhOverThreshold The returned YH over threshold state
3700  * @retval Error code
3701  */
ITDS_isYHOverThreshold(WE_sensorInterface_t * sensorInterface,ITDS_state_t * yhOverThreshold)3702 int8_t ITDS_isYHOverThreshold(WE_sensorInterface_t* sensorInterface, ITDS_state_t *yhOverThreshold)
3703 {
3704   ITDS_6dEvent_t event6d;
3705 
3706   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_6D_EVENT_REG, 1, (uint8_t *) &event6d))
3707   {
3708     return WE_FAIL;
3709   }
3710 
3711   *yhOverThreshold = (ITDS_state_t) event6d.yhOverThreshold;
3712   return WE_SUCCESS;
3713 }
3714 
3715 /**
3716  * @brief Read the ZL over threshold state (6D orientation)
3717  * @param[in] sensorInterface Pointer to sensor interface
3718  * @param[out] zlOverThreshold The returned ZL over threshold state
3719  * @retval Error code
3720  */
ITDS_isZLOverThreshold(WE_sensorInterface_t * sensorInterface,ITDS_state_t * zlOverThreshold)3721 int8_t ITDS_isZLOverThreshold(WE_sensorInterface_t* sensorInterface, ITDS_state_t *zlOverThreshold)
3722 {
3723   ITDS_6dEvent_t event6d;
3724 
3725   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_6D_EVENT_REG, 1, (uint8_t *) &event6d))
3726   {
3727     return WE_FAIL;
3728   }
3729 
3730   *zlOverThreshold = (ITDS_state_t) event6d.zlOverThreshold;
3731 
3732   return WE_SUCCESS;
3733 }
3734 
3735 /**
3736  * @brief Read the ZH over threshold state (6D orientation)
3737  * @param[in] sensorInterface Pointer to sensor interface
3738  * @param[out] zhOverThreshold The returned ZH over threshold state
3739  * @retval Error code
3740  */
ITDS_isZHOverThreshold(WE_sensorInterface_t * sensorInterface,ITDS_state_t * zhOverThreshold)3741 int8_t ITDS_isZHOverThreshold(WE_sensorInterface_t* sensorInterface, ITDS_state_t *zhOverThreshold)
3742 {
3743   ITDS_6dEvent_t event6d;
3744 
3745   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_6D_EVENT_REG, 1, (uint8_t *) &event6d))
3746   {
3747     return WE_FAIL;
3748   }
3749 
3750   *zhOverThreshold = (ITDS_state_t) event6d.zhOverThreshold;
3751 
3752   return WE_SUCCESS;
3753 }
3754 
3755 
3756 /* ALL_INT_EVENT */
3757 
3758 /**
3759  * @brief Read register containing info on all interrupt events
3760  * @param[in] sensorInterface Pointer to sensor interface
3761  * @param[out] events The returned interrupt events status
3762  * @retval Error code
3763  */
ITDS_getAllInterruptEvents(WE_sensorInterface_t * sensorInterface,ITDS_allInterruptEvents_t * events)3764 int8_t ITDS_getAllInterruptEvents(WE_sensorInterface_t* sensorInterface, ITDS_allInterruptEvents_t *events)
3765 {
3766   return ITDS_ReadReg(sensorInterface, ITDS_ALL_INT_EVENT_REG, 1, (uint8_t *) events);
3767 }
3768 
3769 /**
3770  * @brief Read the sleep change interrupt event state
3771  * @param[in] sensorInterface Pointer to sensor interface
3772  * @param[out] sleep The returned sleep change interrupt event state
3773  * @retval Error code
3774  */
ITDS_isSleepChangeEvent(WE_sensorInterface_t * sensorInterface,ITDS_state_t * sleep)3775 int8_t ITDS_isSleepChangeEvent(WE_sensorInterface_t* sensorInterface, ITDS_state_t *sleep)
3776 {
3777   ITDS_allInterruptEvents_t allInterrupts;
3778 
3779   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_ALL_INT_EVENT_REG, 1, (uint8_t *) &allInterrupts))
3780   {
3781     return WE_FAIL;
3782   }
3783 
3784   *sleep = (ITDS_state_t) allInterrupts.sleepChangeState;
3785 
3786   return WE_SUCCESS;
3787 }
3788 
3789 
3790 /* X_Y_Z_OFS_USR */
3791 
3792 /**
3793  * @brief Set the user offset for axis X (for output data and/or wake-up)
3794  * @param[in] sensorInterface Pointer to sensor interface
3795  * @param[in] offsetValueXAxis User offset for axis X
3796  * @retval Error code
3797  */
ITDS_setOffsetValueX(WE_sensorInterface_t * sensorInterface,int8_t offsetValueXAxis)3798 int8_t ITDS_setOffsetValueX(WE_sensorInterface_t* sensorInterface, int8_t offsetValueXAxis)
3799 {
3800   return ITDS_WriteReg(sensorInterface, ITDS_X_OFS_USR_REG, 1, (uint8_t *) &offsetValueXAxis);
3801 }
3802 
3803 /**
3804  * @brief Read the user offset for axis X (for output data and/or wake-up)
3805  * @param[in] sensorInterface Pointer to sensor interface
3806  * @param[out] offsetvalueXAxis The returned user offset for axis X.
3807  * @retval Error code
3808  */
ITDS_getOffsetValueX(WE_sensorInterface_t * sensorInterface,int8_t * offsetvalueXAxis)3809 int8_t ITDS_getOffsetValueX(WE_sensorInterface_t* sensorInterface, int8_t *offsetvalueXAxis)
3810 {
3811   return ITDS_ReadReg(sensorInterface, ITDS_X_OFS_USR_REG, 1, (uint8_t *) offsetvalueXAxis);
3812 }
3813 
3814 /**
3815  * @brief Set the user offset for axis Y (for output data and/or wake-up)
3816  * @param[in] sensorInterface Pointer to sensor interface
3817  * @param[in] offsetValueYAxis User offset for axis Y
3818  * @retval Error code
3819  */
ITDS_setOffsetValueY(WE_sensorInterface_t * sensorInterface,int8_t offsetValueYAxis)3820 int8_t ITDS_setOffsetValueY(WE_sensorInterface_t* sensorInterface, int8_t offsetValueYAxis)
3821 {
3822   return ITDS_WriteReg(sensorInterface, ITDS_Y_OFS_USR_REG, 1, (uint8_t *) &offsetValueYAxis);
3823 }
3824 
3825 /**
3826  * @brief Read the user offset for axis Y (for output data and/or wake-up)
3827  * @param[in] sensorInterface Pointer to sensor interface
3828  * @param[out] offsetValueYAxis The returned user offset for axis Y.
3829  * @retval Error code
3830  */
ITDS_getOffsetValueY(WE_sensorInterface_t * sensorInterface,int8_t * offsetValueYAxis)3831 int8_t ITDS_getOffsetValueY(WE_sensorInterface_t* sensorInterface, int8_t *offsetValueYAxis)
3832 {
3833   return ITDS_ReadReg(sensorInterface, ITDS_Y_OFS_USR_REG, 1, (uint8_t *) offsetValueYAxis);
3834 }
3835 
3836 /**
3837  * @brief Set the user offset for axis Z (for output data and/or wake-up)
3838  * @param[in] sensorInterface Pointer to sensor interface
3839  * @param[in] offsetvalueZAxis The user offset for axis Z
3840  * @retval Error code
3841  */
ITDS_setOffsetValueZ(WE_sensorInterface_t * sensorInterface,int8_t offsetvalueZAxis)3842 int8_t ITDS_setOffsetValueZ(WE_sensorInterface_t* sensorInterface, int8_t offsetvalueZAxis)
3843 {
3844   return ITDS_WriteReg(sensorInterface, ITDS_Z_OFS_USR_REG, 1, (uint8_t *) &offsetvalueZAxis);
3845 }
3846 
3847 /**
3848  * @brief Read the user offset for axis Z (for output data and/or wake-up)
3849  * @param[in] sensorInterface Pointer to sensor interface
3850  * @param[out] offsetValueZAxis The returned user offset for axis Z.
3851  * @retval Error code
3852  */
ITDS_getOffsetValueZ(WE_sensorInterface_t * sensorInterface,int8_t * offsetValueZAxis)3853 int8_t ITDS_getOffsetValueZ(WE_sensorInterface_t* sensorInterface, int8_t *offsetValueZAxis)
3854 {
3855   return ITDS_ReadReg(sensorInterface, ITDS_Z_OFS_USR_REG, 1, (uint8_t *) offsetValueZAxis);
3856 }
3857 
3858 
3859 /* CTRL_7 */
3860 
3861 /**
3862  * @brief Select the data ready interrupt mode [latched mode / pulsed mode]
3863  * @param[in] sensorInterface Pointer to sensor interface
3864  * @param[in] drdyPulsed Data ready interrupt mode
3865  * @retval Error code
3866  */
ITDS_setDataReadyPulsed(WE_sensorInterface_t * sensorInterface,ITDS_drdyPulse_t drdyPulsed)3867 int8_t ITDS_setDataReadyPulsed(WE_sensorInterface_t* sensorInterface, ITDS_drdyPulse_t drdyPulsed)
3868 {
3869   ITDS_ctrl7_t ctrl7;
3870 
3871   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
3872   {
3873     return WE_FAIL;
3874   }
3875 
3876   ctrl7.drdyPulse = drdyPulsed;
3877 
3878   return ITDS_WriteReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7);
3879 }
3880 
3881 /**
3882  * @brief Read the data ready interrupt mode [latched mode / pulsed mode]
3883  * @param[in] sensorInterface Pointer to sensor interface
3884  * @param[out] drdyPulsed The returned data ready interrupt mode
3885  * @retval Error code
3886  */
ITDS_isDataReadyPulsed(WE_sensorInterface_t * sensorInterface,ITDS_drdyPulse_t * drdyPulsed)3887 int8_t ITDS_isDataReadyPulsed(WE_sensorInterface_t* sensorInterface, ITDS_drdyPulse_t *drdyPulsed)
3888 {
3889   ITDS_ctrl7_t ctrl7;
3890 
3891   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
3892   {
3893     return WE_FAIL;
3894   }
3895 
3896   *drdyPulsed = (ITDS_drdyPulse_t) ctrl7.drdyPulse;
3897 
3898   return WE_SUCCESS;
3899 }
3900 
3901 /**
3902  * @brief Enable signal routing from INT_1 to INT_0
3903  * @param[in] sensorInterface Pointer to sensor interface
3904  * @param[in] int1OnInt0 Signal routing INT_1 to INT_0 state
3905  * @retval Error code
3906  */
ITDS_setInt1OnInt0(WE_sensorInterface_t * sensorInterface,ITDS_state_t int1OnInt0)3907 int8_t ITDS_setInt1OnInt0(WE_sensorInterface_t* sensorInterface, ITDS_state_t int1OnInt0)
3908 {
3909   ITDS_ctrl7_t ctrl7;
3910 
3911   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
3912   {
3913     return WE_FAIL;
3914   }
3915 
3916   ctrl7.INT1toINT0 = int1OnInt0;
3917 
3918   return ITDS_WriteReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7);
3919 }
3920 
3921 /**
3922  * @brief Check if signal routing from INT_1 to INT_0 is enabled
3923  * @param[in] sensorInterface Pointer to sensor interface
3924  * @param[out] int1OnInt0 The returned routing enable state.
3925  * @retval Error code
3926  */
ITDS_getInt1OnInt0(WE_sensorInterface_t * sensorInterface,ITDS_state_t * int1OnInt0)3927 int8_t ITDS_getInt1OnInt0(WE_sensorInterface_t* sensorInterface, ITDS_state_t *int1OnInt0)
3928 {
3929   ITDS_ctrl7_t ctrl7;
3930 
3931   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
3932   {
3933     return WE_FAIL;
3934   }
3935 
3936   *int1OnInt0 = (ITDS_state_t) ctrl7.INT1toINT0;
3937 
3938   return WE_SUCCESS;
3939 }
3940 
3941 /**
3942  * @brief Enable/disable interrupts
3943  * @param[in] sensorInterface Pointer to sensor interface
3944  * @param[in] interrupts Interrupts enable state
3945  * @retval Error code
3946  */
ITDS_enableInterrupts(WE_sensorInterface_t * sensorInterface,ITDS_state_t interrupts)3947 int8_t ITDS_enableInterrupts(WE_sensorInterface_t* sensorInterface, ITDS_state_t interrupts)
3948 {
3949   ITDS_ctrl7_t ctrl7;
3950 
3951   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
3952   {
3953     return WE_FAIL;
3954   }
3955 
3956   ctrl7.enInterrupts = interrupts;
3957 
3958   return ITDS_WriteReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7);
3959 }
3960 
3961 /**
3962  * @brief Check if interrupts are enabled
3963  * @param[in] sensorInterface Pointer to sensor interface
3964  * @param[out] interrupts The returned interrupts enable state.
3965  * @retval Error code
3966  */
ITDS_areInterruptsEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * interrupts)3967 int8_t ITDS_areInterruptsEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *interrupts)
3968 {
3969   ITDS_ctrl7_t ctrl7;
3970 
3971   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
3972   {
3973     return WE_FAIL;
3974   }
3975 
3976   *interrupts = (ITDS_state_t) ctrl7.enInterrupts;
3977 
3978   return WE_SUCCESS;
3979 }
3980 
3981 /**
3982  * @brief Enable/disable the application of the user offset values to output data
3983  * @param[in] sensorInterface Pointer to sensor interface
3984  * @param[in] applyOffset State
3985  * @retval Error code
3986  */
ITDS_enableApplyOffset(WE_sensorInterface_t * sensorInterface,ITDS_state_t applyOffset)3987 int8_t ITDS_enableApplyOffset(WE_sensorInterface_t* sensorInterface, ITDS_state_t applyOffset)
3988 {
3989   ITDS_ctrl7_t ctrl7;
3990 
3991   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
3992   {
3993     return WE_FAIL;
3994   }
3995 
3996   ctrl7.applyOffset = applyOffset;
3997 
3998   return ITDS_WriteReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7);
3999 }
4000 
4001 /**
4002  * @brief Check if application of user offset values to output data is enabled.
4003  * @param[in] sensorInterface Pointer to sensor interface
4004  * @param[out] applyOffset Returned enable state.
4005  * @retval Error code
4006  */
ITDS_isApplyOffsetEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * applyOffset)4007 int8_t ITDS_isApplyOffsetEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *applyOffset)
4008 {
4009   ITDS_ctrl7_t ctrl7;
4010 
4011   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
4012   {
4013     return WE_FAIL;
4014   }
4015 
4016   *applyOffset = (ITDS_state_t) ctrl7.applyOffset;
4017 
4018   return WE_SUCCESS;
4019 }
4020 
4021 /**
4022  * @brief Enable/disable the application of user offset values to data only for wake-up functions
4023  * @param[in] sensorInterface Pointer to sensor interface
4024  * @param[in] applyOffset State
4025  * @retval Error code
4026  */
ITDS_enableApplyWakeUpOffset(WE_sensorInterface_t * sensorInterface,ITDS_state_t applyOffset)4027 int8_t ITDS_enableApplyWakeUpOffset(WE_sensorInterface_t* sensorInterface, ITDS_state_t applyOffset)
4028 {
4029   ITDS_ctrl7_t ctrl7;
4030 
4031   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
4032   {
4033     return WE_FAIL;
4034   }
4035 
4036   ctrl7.applyWakeUpOffset = applyOffset;
4037 
4038   return ITDS_WriteReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7);
4039 }
4040 
4041 /**
4042  * @brief Check if application user offset values to data only for wake-up functions is enabled
4043  * @param[in] sensorInterface Pointer to sensor interface
4044  * @param[out] applyOffset The returned enable state
4045  * @retval Error code
4046  */
ITDS_isApplyWakeUpOffsetEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * applyOffset)4047 int8_t ITDS_isApplyWakeUpOffsetEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *applyOffset)
4048 {
4049   ITDS_ctrl7_t ctrl7;
4050 
4051   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
4052   {
4053     return WE_FAIL;
4054   }
4055 
4056   *applyOffset = (ITDS_state_t) ctrl7.applyWakeUpOffset;
4057 
4058   return WE_SUCCESS;
4059 }
4060 
4061 /**
4062  * @brief Set the weight of the user offset words
4063  * @param[in] sensorInterface Pointer to sensor interface
4064  * @param[in] offsetWeight Offset weight
4065  * @retval Error code
4066  */
ITDS_setOffsetWeight(WE_sensorInterface_t * sensorInterface,ITDS_state_t offsetWeight)4067 int8_t ITDS_setOffsetWeight(WE_sensorInterface_t* sensorInterface, ITDS_state_t offsetWeight)
4068 {
4069   ITDS_ctrl7_t ctrl7;
4070 
4071   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
4072   {
4073     return WE_FAIL;
4074   }
4075 
4076   ctrl7.userOffset = offsetWeight;
4077 
4078   return ITDS_WriteReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7);
4079 }
4080 
4081 /**
4082  * @brief Read the weight of the user offset words
4083  * @param[in] sensorInterface Pointer to sensor interface
4084  * @param[out] offsetWeight The returned offset weight.
4085  * @retval Error code
4086  */
ITDS_getOffsetWeight(WE_sensorInterface_t * sensorInterface,ITDS_state_t * offsetWeight)4087 int8_t ITDS_getOffsetWeight(WE_sensorInterface_t* sensorInterface, ITDS_state_t *offsetWeight)
4088 {
4089   ITDS_ctrl7_t ctrl7;
4090 
4091   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
4092   {
4093     return WE_FAIL;
4094   }
4095 
4096   *offsetWeight = (ITDS_state_t) ctrl7.userOffset;
4097 
4098   return WE_SUCCESS;
4099 }
4100 
4101 /**
4102  * @brief Enable/disable high pass filter reference mode
4103  * @param[in] sensorInterface Pointer to sensor interface
4104  * @param[in] refMode State
4105  * @retval Error code
4106  */
ITDS_enableHighPassRefMode(WE_sensorInterface_t * sensorInterface,ITDS_state_t refMode)4107 int8_t ITDS_enableHighPassRefMode(WE_sensorInterface_t* sensorInterface, ITDS_state_t refMode)
4108 {
4109   ITDS_ctrl7_t ctrl7;
4110 
4111   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
4112   {
4113     return WE_FAIL;
4114   }
4115 
4116   ctrl7.highPassRefMode = refMode;
4117 
4118   return ITDS_WriteReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7);
4119 }
4120 
4121 /**
4122  * @brief Check if high pass filter reference mode is enabled
4123  * @param[in] sensorInterface Pointer to sensor interface
4124  * @param[out] refMode The returned reference mode state
4125  * @retval Error code
4126  */
ITDS_isHighPassRefModeEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * refMode)4127 int8_t ITDS_isHighPassRefModeEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *refMode)
4128 {
4129   ITDS_ctrl7_t ctrl7;
4130 
4131   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
4132   {
4133     return WE_FAIL;
4134   }
4135 
4136   *refMode = (ITDS_state_t) ctrl7.highPassRefMode;
4137 
4138   return WE_SUCCESS;
4139 }
4140 
4141 /**
4142  * @brief Enable/disable the low pass filter for 6D orientation detection
4143  * @param[in] sensorInterface Pointer to sensor interface
4144  * @param[in] lowPassOn6D Low pass filter enable state
4145  * @retval Error code
4146  */
ITDS_enableLowPassOn6D(WE_sensorInterface_t * sensorInterface,ITDS_state_t lowPassOn6D)4147 int8_t ITDS_enableLowPassOn6D(WE_sensorInterface_t* sensorInterface, ITDS_state_t lowPassOn6D)
4148 {
4149   ITDS_ctrl7_t ctrl7;
4150 
4151   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
4152   {
4153     return WE_FAIL;
4154   }
4155 
4156   ctrl7.lowPassOn6D = lowPassOn6D;
4157 
4158   return ITDS_WriteReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7);
4159 }
4160 
4161 /**
4162  * @brief Check if the low pass filter for 6D orientation detection is enabled
4163  * @param[in] sensorInterface Pointer to sensor interface
4164  * @param[out] lowPassOn6D The returned low pass filter enable state
4165  * @retval Error code
4166  */
ITDS_isLowPassOn6DEnabled(WE_sensorInterface_t * sensorInterface,ITDS_state_t * lowPassOn6D)4167 int8_t ITDS_isLowPassOn6DEnabled(WE_sensorInterface_t* sensorInterface, ITDS_state_t *lowPassOn6D)
4168 {
4169   ITDS_ctrl7_t ctrl7;
4170 
4171   if (WE_FAIL == ITDS_ReadReg(sensorInterface, ITDS_CTRL_7_REG, 1, (uint8_t *) &ctrl7))
4172   {
4173     return WE_FAIL;
4174   }
4175 
4176   *lowPassOn6D = (ITDS_state_t) ctrl7.lowPassOn6D;
4177 
4178   return WE_SUCCESS;
4179 }
4180