Welcome to mirror list, hosted at ThFree Co, Russian Federation.

hts221.c « hts221 « Components « BSP « Drivers - github.com/Flipper-Zero/STM32CubeWB.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: eb0f26a8595918a3d1b58bc4df9f49b58381019a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
/**
 ******************************************************************************
 * @file    hts221.c
 * @author  MEMS Software Solutions Team
 * @brief   HTS221 driver file
 ******************************************************************************
 * @attention
 *
 * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
 * All rights reserved.</center></h2>
 *
 * This software component is licensed by ST under BSD 3-Clause license,
 * the "License"; You may not use this file except in compliance with the
 * License. You may obtain a copy of the License at:
 *                        opensource.org/licenses/BSD-3-Clause
 *
 ******************************************************************************
 */

/* Includes ------------------------------------------------------------------*/
#include "hts221.h"

/** @addtogroup BSP BSP
 * @{
 */

/** @addtogroup Component Component
 * @{
 */

/** @defgroup HTS221 HTS221
 * @{
 */

/** @defgroup HTS221_Exported_Variables HTS221 Exported Variables
 * @{
 */

HTS221_CommonDrv_t HTS221_COMMON_Driver =
{
  HTS221_Init,
  HTS221_DeInit,
  HTS221_ReadID,
  HTS221_GetCapabilities,
};

HTS221_HUM_Drv_t HTS221_HUM_Driver =
{
  HTS221_HUM_Enable,
  HTS221_HUM_Disable,
  HTS221_HUM_GetOutputDataRate,
  HTS221_HUM_SetOutputDataRate,
  HTS221_HUM_GetHumidity,
};

HTS221_TEMP_Drv_t HTS221_TEMP_Driver =
{
  HTS221_TEMP_Enable,
  HTS221_TEMP_Disable,
  HTS221_TEMP_GetOutputDataRate,
  HTS221_TEMP_SetOutputDataRate,
  HTS221_TEMP_GetTemperature,
};

/**
 * @}
 */

/** @defgroup HTS221_Private_Function_Prototypes HTS221 Private Function Prototypes
 * @{
 */

static int32_t ReadRegWrap(void *Handle, uint8_t Reg, uint8_t *pData, uint16_t Length);
static int32_t WriteRegWrap(void *Handle, uint8_t Reg, uint8_t *pData, uint16_t Length);
static int32_t HTS221_GetOutputDataRate(HTS221_Object_t *pObj, float *Odr);
static int32_t HTS221_SetOutputDataRate(HTS221_Object_t *pObj, float Odr);
static int32_t HTS221_Initialize(HTS221_Object_t *pObj);
static float Linear_Interpolation(lin_t *Lin, float Coeff);

/**
 * @}
 */

/** @defgroup HTS221_Exported_Functions HTS221 Exported Functions
 * @{
 */

/**
 * @brief  Register Component Bus IO operations
 * @param  pObj the device pObj
 * @retval 0 in case of success, an error code otherwise
 */
int32_t HTS221_RegisterBusIO(HTS221_Object_t *pObj, HTS221_IO_t *pIO)
{
  int32_t ret;

  if (pObj == NULL)
  {
    ret = HTS221_ERROR;
  }
  else
  {
    pObj->IO.Init      = pIO->Init;
    pObj->IO.DeInit    = pIO->DeInit;
    pObj->IO.BusType   = pIO->BusType;
    pObj->IO.Address   = pIO->Address;
    pObj->IO.WriteReg  = pIO->WriteReg;
    pObj->IO.ReadReg   = pIO->ReadReg;
    pObj->IO.GetTick   = pIO->GetTick;

    pObj->Ctx.read_reg  = ReadRegWrap;
    pObj->Ctx.write_reg = WriteRegWrap;
    pObj->Ctx.handle   = pObj;

    if (pObj->IO.Init != NULL)
    {
      ret = pObj->IO.Init();
    }
    else
    {
      ret = HTS221_ERROR;
    }
  }

  return ret;
}

/**
 * @brief  Initialize the HTS221 sensor
 * @param  pObj the device pObj
 * @retval 0 in case of success, an error code otherwise
 */
int32_t HTS221_Init(HTS221_Object_t *pObj)
{
  if (pObj->is_initialized == 0U)
  {
    if (HTS221_Initialize(pObj) != HTS221_OK)
    {
      return HTS221_ERROR;
    }
  }

  pObj->is_initialized = 1;

  return HTS221_OK;
}

/**
 * @brief  Deinitialize the HTS221 sensor
 * @param  pObj the device pObj
 * @retval 0 in case of success, an error code otherwise
 */
int32_t HTS221_DeInit(HTS221_Object_t *pObj)
{
  if (pObj->is_initialized == 1U)
  {
    if (HTS221_HUM_Disable(pObj) != HTS221_OK)
    {
      return HTS221_ERROR;
    }

    if (HTS221_TEMP_Disable(pObj) != HTS221_OK)
    {
      return HTS221_ERROR;
    }
  }

  pObj->is_initialized = 0;

  return HTS221_OK;
}

/**
 * @brief  Get WHO_AM_I value
 * @param  pObj the device pObj
 * @param  Id the WHO_AM_I value
 * @retval 0 in case of success, an error code otherwise
 */
int32_t HTS221_ReadID(HTS221_Object_t *pObj, uint8_t *Id)
{
  if (hts221_device_id_get(&(pObj->Ctx), Id) != HTS221_OK)
  {
    return HTS221_ERROR;
  }

  return HTS221_OK;
}

/**
 * @brief  Get HTS221 sensor capabilities
 * @param  pObj Component object pointer
 * @param  Capabilities pointer to HTS221 sensor capabilities
 * @retval 0 in case of success, an error code otherwise
 */
int32_t HTS221_GetCapabilities(HTS221_Object_t *pObj, HTS221_Capabilities_t *Capabilities)
{
  /* Prevent unused argument(s) compilation warning */
  (void)(pObj);

  Capabilities->Humidity    = 1;
  Capabilities->Pressure    = 0;
  Capabilities->Temperature = 1;
  Capabilities->LowPower    = 0;
  Capabilities->HumMaxOdr   = 12.5f;
  Capabilities->TempMaxOdr  = 12.5f;
  Capabilities->PressMaxOdr = 0.0f;
  return HTS221_OK;
}

/**
 * @brief  Get the HTS221 initialization status
 * @param  pObj the device pObj
 * @param  Status 1 if initialized, 0 otherwise
 * @retval 0 in case of success, an error code otherwise
 */
int32_t HTS221_Get_Init_Status(HTS221_Object_t *pObj, uint8_t *Status)
{
  if (pObj == NULL)
  {
    return HTS221_ERROR;
  }

  *Status = pObj->is_initialized;

  return HTS221_OK;
}

/**
 * @brief  Enable the HTS221 humidity sensor
 * @param  pObj the device pObj
 * @retval 0 in case of success, an error code otherwise
 */
int32_t HTS221_HUM_Enable(HTS221_Object_t *pObj)
{
  /* Check if the component is already enabled */
  if (pObj->hum_is_enabled == 1U)
  {
    return HTS221_OK;
  }

  /* Check if the HTS221 temperature sensor is already enabled. */
  /* If yes, skip the enable function, if not call enable function */
  if (pObj->temp_is_enabled == 0U)
  {
    /* Power on the component. */
    if (hts221_power_on_set(&(pObj->Ctx), PROPERTY_ENABLE) != HTS221_OK)
    {
      return HTS221_ERROR;
    }
  }

  pObj->hum_is_enabled = 1;

  return HTS221_OK;
}

/**
 * @brief  Disable the HTS221 humidity sensor
 * @param  pObj the device pObj
 * @retval 0 in case of success, an error code otherwise
 */
int32_t HTS221_HUM_Disable(HTS221_Object_t *pObj)
{
  /* Check if the component is already disabled */
  if (pObj->hum_is_enabled == 0U)
  {
    return HTS221_OK;
  }

  /* Check if the HTS221 temperature sensor is still enable. */
  /* If yes, skip the disable function, if not call disable function */
  if (pObj->temp_is_enabled == 0U)
  {
    /* Power off the component. */
    if (hts221_power_on_set(&(pObj->Ctx), PROPERTY_DISABLE) != HTS221_OK)
    {
      return HTS221_ERROR;
    }
  }

  pObj->hum_is_enabled = 0;

  return HTS221_OK;
}

/**
 * @brief  Get the HTS221 humidity sensor output data rate
 * @param  pObj the device pObj
 * @param  Odr pointer where the output data rate is written
 * @retval 0 in case of success, an error code otherwise
 */
int32_t HTS221_HUM_GetOutputDataRate(HTS221_Object_t *pObj, float *Odr)
{
  return HTS221_GetOutputDataRate(pObj, Odr);
}

/**
 * @brief  Set the HTS221 humidity sensor output data rate
 * @param  pObj the device pObj
 * @param  Odr the output data rate value to be set
 * @retval 0 in case of success, an error code otherwise
 */
int32_t HTS221_HUM_SetOutputDataRate(HTS221_Object_t *pObj, float Odr)
{
  return HTS221_SetOutputDataRate(pObj, Odr);
}

/**
 * @brief  Get the HTS221 humidity value
 * @param  pObj the device pObj
 * @param  Value pointer where the humidity value is written
 * @retval 0 in case of success, an error code otherwise
 */
int32_t HTS221_HUM_GetHumidity(HTS221_Object_t *pObj, float *Value)
{
  axis1bit16_t data_raw_humidity;
  axis1bit16_t coeff;
  lin_t lin_hum;

  if (hts221_hum_adc_point_0_get(&(pObj->Ctx), coeff.u8bit) != HTS221_OK)
  {
    return HTS221_ERROR;
  }

  lin_hum.x0 = (float)coeff.i16bit;

  if (hts221_hum_rh_point_0_get(&(pObj->Ctx), coeff.u8bit) != HTS221_OK)
  {
    return HTS221_ERROR;
  }

  lin_hum.y0 = (float)coeff.u8bit[0];

  if (hts221_hum_adc_point_1_get(&(pObj->Ctx), coeff.u8bit) != HTS221_OK)
  {
    return HTS221_ERROR;
  }

  lin_hum.x1 = (float)coeff.i16bit;

  if (hts221_hum_rh_point_1_get(&(pObj->Ctx), coeff.u8bit) != HTS221_OK)
  {
    return HTS221_ERROR;
  }

  lin_hum.y1 = (float)coeff.u8bit[0];

  (void)memset(data_raw_humidity.u8bit, 0x00, sizeof(int16_t));
  if (hts221_humidity_raw_get(&(pObj->Ctx), data_raw_humidity.u8bit) != HTS221_OK)
  {
    return HTS221_ERROR;
  }

  *Value = Linear_Interpolation(&lin_hum, (float)data_raw_humidity.i16bit);

  if (*Value < 0.0f)
  {
    *Value = 0.0f;
  }

  if (*Value > 100.0f)
  {
    *Value = 100.0f;
  }

  return HTS221_OK;
}

/**
 * @brief  Get the HTS221 humidity data ready bit value
 * @param  pObj the device pObj
 * @param  Status the status of data ready bit
 * @retval 0 in case of success, an error code otherwise
 */
int32_t HTS221_HUM_Get_DRDY_Status(HTS221_Object_t *pObj, uint8_t *Status)
{
  if (hts221_hum_data_ready_get(&(pObj->Ctx), Status) != HTS221_OK)
  {
    return HTS221_ERROR;
  }

  return HTS221_OK;
}

/**
 * @brief  Enable the HTS221 temperature sensor
 * @param  pObj the device pObj
 * @retval 0 in case of success, an error code otherwise
 */
int32_t HTS221_TEMP_Enable(HTS221_Object_t *pObj)
{
  /* Check if the component is already enabled */
  if (pObj->temp_is_enabled == 1U)
  {
    return HTS221_OK;
  }

  /* Check if the HTS221 humidity sensor is already enabled. */
  /* If yes, skip the enable function, if not call enable function */
  if (pObj->hum_is_enabled == 0U)
  {
    /* Power on the component. */
    if (hts221_power_on_set(&(pObj->Ctx), PROPERTY_ENABLE) != HTS221_OK)
    {
      return HTS221_ERROR;
    }
  }

  pObj->temp_is_enabled = 1;

  return HTS221_OK;
}

/**
 * @brief  Disable the HTS221 temperature sensor
 * @param  pObj the device pObj
 * @retval 0 in case of success, an error code otherwise
 */
int32_t HTS221_TEMP_Disable(HTS221_Object_t *pObj)
{
  /* Check if the component is already disabled */
  if (pObj->temp_is_enabled == 0U)
  {
    return HTS221_OK;
  }

  /* Check if the HTS221 humidity sensor is still enable. */
  /* If yes, skip the disable function, if not call disable function */
  if (pObj->hum_is_enabled == 0U)
  {
    /* Power off the component. */
    if (hts221_power_on_set(&(pObj->Ctx), PROPERTY_DISABLE) != HTS221_OK)
    {
      return HTS221_ERROR;
    }
  }

  pObj->temp_is_enabled = 0;

  return HTS221_OK;
}

/**
 * @brief  Get the HTS221 temperature sensor output data rate
 * @param  pObj the device pObj
 * @param  Odr pointer where the output data rate is written
 * @retval 0 in case of success, an error code otherwise
 */
int32_t HTS221_TEMP_GetOutputDataRate(HTS221_Object_t *pObj, float *Odr)
{
  return HTS221_GetOutputDataRate(pObj, Odr);
}

/**
 * @brief  Set the HTS221 temperature sensor output data rate
 * @param  pObj the device pObj
 * @param  Odr the output data rate value to be set
 * @retval 0 in case of success, an error code otherwise
 */
int32_t HTS221_TEMP_SetOutputDataRate(HTS221_Object_t *pObj, float Odr)
{
  return HTS221_SetOutputDataRate(pObj, Odr);
}

/**
 * @brief  Get the HTS221 temperature value
 * @param  pObj the device pObj
 * @param  Value pointer where the temperature value is written
 * @retval 0 in case of success, an error code otherwise
 */
int32_t HTS221_TEMP_GetTemperature(HTS221_Object_t *pObj, float *Value)
{
  axis1bit16_t data_raw_temperature;
  axis1bit16_t coeff;
  lin_t lin_temp;

  if (hts221_temp_adc_point_0_get(&(pObj->Ctx), coeff.u8bit) != HTS221_OK)
  {
    return HTS221_ERROR;
  }

  lin_temp.x0 = (float)coeff.i16bit;

  if (hts221_temp_deg_point_0_get(&(pObj->Ctx), coeff.u8bit) != HTS221_OK)
  {
    return HTS221_ERROR;
  }

  lin_temp.y0 = (float)coeff.u8bit[0];

  if (hts221_temp_adc_point_1_get(&(pObj->Ctx), coeff.u8bit) != HTS221_OK)
  {
    return HTS221_ERROR;
  }

  lin_temp.x1 = (float)coeff.i16bit;

  if (hts221_temp_deg_point_1_get(&(pObj->Ctx), coeff.u8bit) != HTS221_OK)
  {
    return HTS221_ERROR;
  }

  lin_temp.y1 = (float)coeff.u8bit[0];

  (void)memset(data_raw_temperature.u8bit, 0x00, sizeof(int16_t));
  if (hts221_temperature_raw_get(&(pObj->Ctx), data_raw_temperature.u8bit) != HTS221_OK)
  {
    return HTS221_ERROR;
  }

  *Value = Linear_Interpolation(&lin_temp, (float)data_raw_temperature.i16bit);

  return HTS221_OK;
}

/**
 * @brief  Get the HTS221 temperature data ready bit value
 * @param  pObj the device pObj
 * @param  Status the status of data ready bit
 * @retval 0 in case of success, an error code otherwise
 */
int32_t HTS221_TEMP_Get_DRDY_Status(HTS221_Object_t *pObj, uint8_t *Status)
{
  if (hts221_temp_data_ready_get(&(pObj->Ctx), Status) != HTS221_OK)
  {
    return HTS221_ERROR;
  }

  return HTS221_OK;
}

/**
 * @brief  Set the HTS221 One Shot Mode
 * @param  pObj the device pObj
 * @retval 0 in case of success, an error code otherwise
 */
int32_t HTS221_Set_One_Shot(HTS221_Object_t *pObj)
{

  /* Set ODR */
  if(hts221_data_rate_set(&(pObj->Ctx), HTS221_ONE_SHOT)!= HTS221_OK)
  {
    return HTS221_ERROR;
  }
  
  /* Start One Shot Measurement */
  if(hts221_one_shoot_trigger_set(&(pObj->Ctx), 1) != HTS221_OK)
  {
    return HTS221_ERROR;
  }
  
  return HTS221_OK;
}

/**
 * @brief  Get the HTS221 One Shot Status
 * @param  pObj the device pObj
 * @param  Status pointer to the one shot status (1 means measurements available, 0 means measurements not available yet)
 * @retval 0 in case of success, an error code otherwise
 */
int32_t HTS221_Get_One_Shot_Status(HTS221_Object_t *pObj, uint8_t *Status)
{
  uint8_t h_da;
  uint8_t t_da;

  /* Get DataReady for humidity */
  if(hts221_hum_data_ready_get(&(pObj->Ctx), &h_da) != HTS221_OK)
  {
    return HTS221_ERROR;
  }

  /* Get DataReady for temperature */
  if(hts221_temp_data_ready_get(&(pObj->Ctx), &t_da) != HTS221_OK)
  {
    return HTS221_ERROR;
  }

  if(h_da && t_da)
  {
    *Status = 1;
  }
  else
  {
    *Status = 0;
  }

  return HTS221_OK;
}

/**
 * @brief  Get the HTS221 register value
 * @param  pObj the device pObj
 * @param  Reg address to be read
 * @param  Data pointer where the value is written
 * @retval 0 in case of success, an error code otherwise
 */
int32_t HTS221_Read_Reg(HTS221_Object_t *pObj, uint8_t Reg, uint8_t *Data)
{
  if (hts221_read_reg(&(pObj->Ctx), Reg, Data, 1) != HTS221_OK)
  {
    return HTS221_ERROR;
  }

  return HTS221_OK;
}

/**
 * @brief  Set the HTS221 register value
 * @param  pObj the device pObj
 * @param  Reg address to be written
 * @param  Data value to be written
 * @retval 0 in case of success, an error code otherwise
 */
int32_t HTS221_Write_Reg(HTS221_Object_t *pObj, uint8_t Reg, uint8_t Data)
{
  if (hts221_write_reg(&(pObj->Ctx), Reg, &Data, 1) != HTS221_OK)
  {
    return HTS221_ERROR;
  }

  return HTS221_OK;
}

/**
 * @}
 */

/** @defgroup HTS221_Private_Functions HTS221 Private Functions
 * @{
 */

/**
 * @brief  Get output data rate
 * @param  pObj the device pObj
 * @param  Odr the output data rate value
 * @retval 0 in case of success, an error code otherwise
 */
static int32_t HTS221_GetOutputDataRate(HTS221_Object_t *pObj, float *Odr)
{
  int32_t ret = HTS221_OK;
  hts221_odr_t odr_low_level;

  if (hts221_data_rate_get(&(pObj->Ctx), &odr_low_level) != HTS221_OK)
  {
    return HTS221_ERROR;
  }

  switch (odr_low_level)
  {
    case HTS221_ONE_SHOT:
      *Odr = 0.0f;
      break;

    case HTS221_ODR_1Hz:
      *Odr = 1.0f;
      break;

    case HTS221_ODR_7Hz:
      *Odr = 7.0f;
      break;

    case HTS221_ODR_12Hz5:
      *Odr = 12.5f;
      break;

    default:
      ret = HTS221_ERROR;
      break;
  }

  return ret;
}

/**
 * @brief  Set output data rate
 * @param  pObj the device pObj
 * @param  Odr the output data rate value to be set
 * @retval 0 in case of success, an error code otherwise
 */
static int32_t HTS221_SetOutputDataRate(HTS221_Object_t *pObj, float Odr)
{
  hts221_odr_t new_odr;

  new_odr = (Odr <= 1.0f) ? HTS221_ODR_1Hz
            : (Odr <= 7.0f) ? HTS221_ODR_7Hz
            :                 HTS221_ODR_12Hz5;

  if (hts221_data_rate_set(&(pObj->Ctx), new_odr) != HTS221_OK)
  {
    return HTS221_ERROR;
  }

  return HTS221_OK;
}

/**
 * @brief  Initialize the HTS221 sensor
 * @param  pObj the device pObj
 * @retval 0 in case of success, an error code otherwise
 */
static int32_t HTS221_Initialize(HTS221_Object_t *pObj)
{
  /* Power off the component. */
  if (hts221_power_on_set(&(pObj->Ctx), PROPERTY_DISABLE) != HTS221_OK)
  {
    return HTS221_ERROR;
  }

  /* Enable BDU */
  if (hts221_block_data_update_set(&(pObj->Ctx), PROPERTY_ENABLE) != HTS221_OK)
  {
    return HTS221_ERROR;
  }

  /* Set default ODR */
  if (HTS221_SetOutputDataRate(pObj, 1.0f) != HTS221_OK)
  {
    return HTS221_ERROR;
  }

  return HTS221_OK;
}

/**
 * @brief  Enable HTS221 DRDY interrupt mode
 * @param  pObj the device pObj
 * @retval 0 in case of success, an error code otherwise
 */
int32_t HTS221_Enable_DRDY_Interrupt(HTS221_Object_t *pObj)
{
  if (hts221_drdy_on_int_set(&(pObj->Ctx), PROPERTY_ENABLE) != HTS221_OK)
  {
    return HTS221_ERROR;
  }  
  
  return HTS221_OK;
}

/**
 * @brief  Function used to apply coefficient
 * @param  Lin the line
 * @param  Coeff the coefficient
 * @retval Calculation result
 */
static float Linear_Interpolation(lin_t *Lin, float Coeff)
{
  return (((Lin->y1 - Lin->y0) * Coeff) + ((Lin->x1 * Lin->y0) - (Lin->x0 * Lin->y1))) / (Lin->x1 - Lin->x0);
}

/**
 * @brief  Wrap Read register component function to Bus IO function
 * @param  Handle the device handler
 * @param  Reg the register address
 * @param  pData the stored data pointer
 * @param  Length the length
 * @retval 0 in case of success, an error code otherwise
 */
static int32_t ReadRegWrap(void *Handle, uint8_t Reg, uint8_t *pData, uint16_t Length)
{
  HTS221_Object_t *pObj = (HTS221_Object_t *)Handle;

  if (pObj->IO.BusType == (uint32_t)HTS221_I2C_BUS) /* I2C */
  {
    /* Enable Multi-byte read */
    return pObj->IO.ReadReg(pObj->IO.Address, (Reg | 0x80U), pData, Length);
  }
  else /* SPI 3-Wires */
  {
    /* Enable Multi-byte read */
    return pObj->IO.ReadReg(pObj->IO.Address, (Reg | 0x40U), pData, Length);
  }
}

/**
 * @brief  Wrap Write register component function to Bus IO function
 * @param  Handle the device handler
 * @param  Reg the register address
 * @param  pData the stored data pointer
 * @param  Length the length
 * @retval 0 in case of success, an error code otherwise
 */
static int32_t WriteRegWrap(void *Handle, uint8_t Reg, uint8_t *pData, uint16_t Length)
{
  HTS221_Object_t *pObj = (HTS221_Object_t *)Handle;

  if (pObj->IO.BusType == (uint32_t)HTS221_I2C_BUS) /* I2C */
  {
    /* Enable Multi-byte write */
    return pObj->IO.WriteReg(pObj->IO.Address, (Reg | 0x80U), pData, Length);
  }
  else /* SPI 3-Wires */
  {
    /* Enable Multi-byte write */
    return pObj->IO.WriteReg(pObj->IO.Address, (Reg | 0x40U), pData, Length);
  }
}

/**
  * @}
  */

/**
  * @}
  */

/**
  * @}
  */

/**
  * @}
  */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/