LibDriver HDC2080
Loading...
Searching...
No Matches
driver_hdc2080.c
Go to the documentation of this file.
1
36
37#include "driver_hdc2080.h"
38
42#define CHIP_NAME "Texas Instruments HDC2080"
43#define MANUFACTURER_NAME "Texas Instruments"
44#define SUPPLY_VOLTAGE_MIN 1.62f
45#define SUPPLY_VOLTAGE_MAX 3.6f
46#define MAX_CURRENT 90.0f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 125.0f
49#define DRIVER_VERSION 1000
50
54#define HDC2080_REG_TEMPERATURE_LOW 0x00
55#define HDC2080_REG_TEMPERATURE_HIGH 0x01
56#define HDC2080_REG_HUMIDITY_LOW 0x02
57#define HDC2080_REG_HUMIDITY_HIGH 0x03
58#define HDC2080_REG_INTERRUPT_DRDY 0x04
59#define HDC2080_REG_TEMPERATURE_MAX 0x05
60#define HDC2080_REG_HUMIDITY_MAX 0x06
61#define HDC2080_REG_INTERRUPT_ENABLE 0x07
62#define HDC2080_REG_TEMP_OFFSET_ADJUST 0x08
63#define HDC2080_REG_HUM_OFFSET_ADJUST 0x09
64#define HDC2080_REG_TEMP_THR_L 0x0A
65#define HDC2080_REG_TEMP_THR_H 0x0B
66#define HDC2080_REG_RH_THR_L 0x0C
67#define HDC2080_REG_RH_THR_H 0x0D
68#define HDC2080_REG_CONF 0x0E
69#define HDC2080_REG_MEASUREMENT 0x0F
70#define HDC2080_REG_MANUFACTURER_ID_LOW 0xFC
71#define HDC2080_REG_MANUFACTURER_ID_HIGH 0xFD
72#define HDC2080_REG_DEVICE_ID_LOW 0xFE
73#define HDC2080_REG_DEVICE_ID_HIGH 0xFF
74
86static uint8_t a_hdc2080_iic_read(hdc2080_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
87{
88 if (handle->iic_read(handle->iic_addr, reg, buf, len) != 0) /* read the register */
89 {
90 return 1; /* return error */
91 }
92 else
93 {
94 return 0; /* success return 0 */
95 }
96}
97
109static uint8_t a_hdc2080_iic_write(hdc2080_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
110{
111 if (handle->iic_write(handle->iic_addr, reg, buf, len) != 0) /* write the register */
112 {
113 return 1; /* return error */
114 }
115 else
116 {
117 return 0; /* success return 0 */
118 }
119}
120
131{
132 if (handle == NULL) /* check handle */
133 {
134 return 2; /* return error */
135 }
136
137 handle->iic_addr = (uint8_t)addr_pin; /* set pin */
138
139 return 0; /* success return 0 */
140}
141
152{
153 if (handle == NULL) /* check handle */
154 {
155 return 2; /* return error */
156 }
157
158 *addr_pin = (hdc2080_address_t)(handle->iic_addr); /* get pin */
159
160 return 0; /* success return 0 */
161}
162
177{
178 uint8_t res;
179 uint8_t buf[2];
180 uint16_t id;
181
182 if (handle == NULL) /* check handle */
183 {
184 return 2; /* return error */
185 }
186 if (handle->debug_print == NULL) /* check debug_print */
187 {
188 return 3; /* return error */
189 }
190 if (handle->iic_init == NULL) /* check iic_init */
191 {
192 handle->debug_print("hdc2080: iic_init is null.\n"); /* iic_init is null */
193
194 return 3; /* return error */
195 }
196 if (handle->iic_deinit == NULL) /* check iic_deinit */
197 {
198 handle->debug_print("hdc2080: iic_deinit is null.\n"); /* iic_deinit is null */
199
200 return 3; /* return error */
201 }
202 if (handle->iic_read == NULL) /* check iic_read */
203 {
204 handle->debug_print("hdc2080: iic_read is null.\n"); /* iic_read is null */
205
206 return 3; /* return error */
207 }
208 if (handle->iic_write == NULL) /* check iic_write */
209 {
210 handle->debug_print("hdc2080: iic_write is null.\n"); /* iic_write is null */
211
212 return 3; /* return error */
213 }
214 if (handle->delay_ms == NULL) /* check delay_ms */
215 {
216 handle->debug_print("hdc2080: delay_ms is null.\n"); /* delay_ms is null */
217
218 return 3; /* return error */
219 }
220
221 if (handle->iic_init() != 0) /* iic init */
222 {
223 handle->debug_print("hdc2080: iic init failed.\n"); /* iic init failed */
224
225 return 1; /* return error */
226 }
227 res = a_hdc2080_iic_read(handle, HDC2080_REG_MANUFACTURER_ID_LOW, buf, 2); /* read manufacturer id */
228 if (res != 0) /* check result */
229 {
230 handle->debug_print("hdc2080: read manufacturer id failed.\n"); /* read manufacturer id failed */
231 (void)handle->iic_deinit(); /* iic deinit */
232
233 return 4; /* return error */
234 }
235 id = buf[0] | (uint16_t)buf[1] << 8; /* set id */
236 if (id != 0x5449) /* check id */
237 {
238 handle->debug_print("hdc2080: manufacturer id is invalid.\n"); /* read manufacturer id failed */
239 (void)handle->iic_deinit(); /* iic deinit */
240
241 return 5; /* return error */
242 }
243 res = a_hdc2080_iic_read(handle, HDC2080_REG_DEVICE_ID_LOW, buf, 2); /* read device id */
244 if (res != 0) /* check result */
245 {
246 handle->debug_print("hdc2080: read device id failed.\n"); /* read device id failed */
247 (void)handle->iic_deinit(); /* iic deinit */
248
249 return 4; /* return error */
250 }
251 id = buf[0] | (uint16_t)buf[1] << 8; /* set id */
252 if (id != 0x07D0) /* check id */
253 {
254 handle->debug_print("hdc2080: device id is invalid.\n"); /* read device id failed */
255 (void)handle->iic_deinit(); /* iic deinit */
256
257 return 5; /* return error */
258 }
259
260 res = a_hdc2080_iic_read(handle, HDC2080_REG_CONF, buf, 1); /* read config */
261 if (res != 0) /* check result */
262 {
263 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
264 (void)handle->iic_deinit(); /* iic deinit */
265
266 return 6; /* return error */
267 }
268 buf[0] &= ~(1 << 7); /* clear settings */
269 buf[0] |= 1 << 7; /* software reset */
270 res = a_hdc2080_iic_write(handle, HDC2080_REG_CONF, buf, 1); /* write config */
271 if (res != 0) /* check result */
272 {
273 handle->debug_print("hdc2080: write config failed.\n"); /* write config failed */
274 (void)handle->iic_deinit(); /* iic deinit */
275
276 return 6; /* return error */
277 }
278 handle->delay_ms(100); /* delay 100ms */
279 handle->inited = 1; /* flag finish initialization */
280
281 return 0; /* success return 0 */
282}
283
295{
296 uint8_t res;
297 uint8_t prev;
298
299 if (handle == NULL) /* check handle */
300 {
301 return 2; /* return error */
302 }
303 if (handle->inited != 1) /* check handle initialization */
304 {
305 return 3; /* return error */
306 }
307
308 res = a_hdc2080_iic_read(handle, HDC2080_REG_CONF, &prev, 1); /* read config */
309 if (res != 0) /* check result */
310 {
311 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
312
313 return 1; /* return error */
314 }
315 prev &= ~(7 << 4); /* clear settings */
316 res = a_hdc2080_iic_write(handle, HDC2080_REG_CONF, &prev, 1); /* write config */
317 if (res != 0) /* check result */
318 {
319 handle->debug_print("hdc2080: write config failed.\n"); /* write config failed */
320
321 return 1; /* return error */
322 }
323 if (handle->iic_deinit() != 0) /* iic deinit */
324 {
325 handle->debug_print("hdc2080: iic deinit failed.\n"); /* iic deinit failed */
326
327 return 1; /* return error */
328 }
329 handle->inited = 0; /* set closed flag */
330
331 return 0; /* success return 0 */
332}
333
346{
347 uint8_t res;
348 uint8_t prev;
349
350 if (handle == NULL) /* check handle */
351 {
352 return 2; /* return error */
353 }
354 if (handle->inited != 1) /* check handle initialization */
355 {
356 return 3; /* return error */
357 }
358
359 res = a_hdc2080_iic_read(handle, HDC2080_REG_MEASUREMENT, &prev, 1); /* read config */
360 if (res != 0) /* check result */
361 {
362 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
363
364 return 1; /* return error */
365 }
366 prev &= ~(3 << 6); /* clear settings */
367 prev |= resolution << 6; /* set resolution */
368 res = a_hdc2080_iic_write(handle, HDC2080_REG_MEASUREMENT, &prev, 1); /* write config */
369 if (res != 0) /* check result */
370 {
371 handle->debug_print("hdc2080: write config failed.\n"); /* write config failed */
372
373 return 1; /* return error */
374 }
375
376 return 0; /* success return 0 */
377}
378
391{
392 uint8_t res;
393 uint8_t prev;
394
395 if (handle == NULL) /* check handle */
396 {
397 return 2; /* return error */
398 }
399 if (handle->inited != 1) /* check handle initialization */
400 {
401 return 3; /* return error */
402 }
403
404 res = a_hdc2080_iic_read(handle, HDC2080_REG_MEASUREMENT, &prev, 1); /* read config */
405 if (res != 0) /* check result */
406 {
407 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
408
409 return 1; /* return error */
410 }
411 *resolution = (hdc2080_resolution_t)((prev >> 6) & 0x3); /* get resolution */
412
413 return 0; /* success return 0 */
414}
415
428{
429 uint8_t res;
430 uint8_t prev;
431
432 if (handle == NULL) /* check handle */
433 {
434 return 2; /* return error */
435 }
436 if (handle->inited != 1) /* check handle initialization */
437 {
438 return 3; /* return error */
439 }
440
441 res = a_hdc2080_iic_read(handle, HDC2080_REG_MEASUREMENT, &prev, 1); /* read config */
442 if (res != 0) /* check result */
443 {
444 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
445
446 return 1; /* return error */
447 }
448 prev &= ~(3 << 4); /* clear settings */
449 prev |= resolution << 4; /* set resolution */
450 res = a_hdc2080_iic_write(handle, HDC2080_REG_MEASUREMENT, &prev, 1); /* write config */
451 if (res != 0) /* check result */
452 {
453 handle->debug_print("hdc2080: write config failed.\n"); /* write config failed */
454
455 return 1; /* return error */
456 }
457
458 return 0; /* success return 0 */
459}
460
473{
474 uint8_t res;
475 uint8_t prev;
476
477 if (handle == NULL) /* check handle */
478 {
479 return 2; /* return error */
480 }
481 if (handle->inited != 1) /* check handle initialization */
482 {
483 return 3; /* return error */
484 }
485
486 res = a_hdc2080_iic_read(handle, HDC2080_REG_MEASUREMENT, &prev, 1); /* read config */
487 if (res != 0) /* check result */
488 {
489 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
490
491 return 1; /* return error */
492 }
493 *resolution = (hdc2080_resolution_t)((prev >> 4) & 0x3); /* get resolution */
494
495 return 0; /* success return 0 */
496}
497
510{
511 uint8_t res;
512 uint8_t prev;
513
514 if (handle == NULL) /* check handle */
515 {
516 return 2; /* return error */
517 }
518 if (handle->inited != 1) /* check handle initialization */
519 {
520 return 3; /* return error */
521 }
522
523 res = a_hdc2080_iic_read(handle, HDC2080_REG_MEASUREMENT, &prev, 1); /* read config */
524 if (res != 0) /* check result */
525 {
526 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
527
528 return 1; /* return error */
529 }
530 prev &= ~(3 << 1); /* clear settings */
531 prev |= mode << 1; /* set mode */
532 res = a_hdc2080_iic_write(handle, HDC2080_REG_MEASUREMENT, &prev, 1); /* write config */
533 if (res != 0) /* check result */
534 {
535 handle->debug_print("hdc2080: write config failed.\n"); /* write config failed */
536
537 return 1; /* return error */
538 }
539
540 return 0; /* success return 0 */
541}
542
555{
556 uint8_t res;
557 uint8_t prev;
558
559 if (handle == NULL) /* check handle */
560 {
561 return 2; /* return error */
562 }
563 if (handle->inited != 1) /* check handle initialization */
564 {
565 return 3; /* return error */
566 }
567
568 res = a_hdc2080_iic_read(handle, HDC2080_REG_MEASUREMENT, &prev, 1); /* read config */
569 if (res != 0) /* check result */
570 {
571 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
572
573 return 1; /* return error */
574 }
575 *mode = (hdc2080_mode_t)((prev >> 1) & 0x03); /* get mode */
576
577 return 0; /* success return 0 */
578}
579
592{
593 uint8_t res;
594 uint8_t prev;
595
596 if (handle == NULL) /* check handle */
597 {
598 return 2; /* return error */
599 }
600 if (handle->inited != 1) /* check handle initialization */
601 {
602 return 3; /* return error */
603 }
604
605 res = a_hdc2080_iic_read(handle, HDC2080_REG_MEASUREMENT, &prev, 1); /* read config */
606 if (res != 0) /* check result */
607 {
608 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
609
610 return 1; /* return error */
611 }
612 prev &= ~(1 << 0); /* clear settings */
613 prev |= enable << 0; /* set bool */
614 res = a_hdc2080_iic_write(handle, HDC2080_REG_MEASUREMENT, &prev, 1); /* write config */
615 if (res != 0) /* check result */
616 {
617 handle->debug_print("hdc2080: write config failed.\n"); /* write config failed */
618
619 return 1; /* return error */
620 }
621
622 return 0; /* success return 0 */
623}
624
637{
638 uint8_t res;
639 uint8_t prev;
640
641 if (handle == NULL) /* check handle */
642 {
643 return 2; /* return error */
644 }
645 if (handle->inited != 1) /* check handle initialization */
646 {
647 return 3; /* return error */
648 }
649
650 res = a_hdc2080_iic_read(handle, HDC2080_REG_MEASUREMENT, &prev, 1); /* read config */
651 if (res != 0) /* check result */
652 {
653 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
654
655 return 1; /* return error */
656 }
657 *enable = (hdc2080_bool_t)((prev >> 0) & 0x01); /* get bool */
658
659 return 0; /* success return 0 */
660}
661
673{
674 uint8_t res;
675 uint8_t prev;
676
677 if (handle == NULL) /* check handle */
678 {
679 return 2; /* return error */
680 }
681 if (handle->inited != 1) /* check handle initialization */
682 {
683 return 3; /* return error */
684 }
685
686 res = a_hdc2080_iic_read(handle, HDC2080_REG_CONF, &prev, 1); /* read config */
687 if (res != 0) /* check result */
688 {
689 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
690
691 return 1; /* return error */
692 }
693 prev &= ~(1 << 7); /* clear settings */
694 prev |= 1 << 7; /* set soft reset */
695 res = a_hdc2080_iic_write(handle, HDC2080_REG_CONF, &prev, 1); /* write config */
696 if (res != 0) /* check result */
697 {
698 handle->debug_print("hdc2080: write config failed.\n"); /* write config failed */
699
700 return 1; /* return error */
701 }
702 handle->delay_ms(100); /* delay 100ms */
703
704 return 0; /* success return 0 */
705}
706
719{
720 uint8_t res;
721 uint8_t prev;
722
723 if (handle == NULL) /* check handle */
724 {
725 return 2; /* return error */
726 }
727 if (handle->inited != 1) /* check handle initialization */
728 {
729 return 3; /* return error */
730 }
731
732 res = a_hdc2080_iic_read(handle, HDC2080_REG_CONF, &prev, 1); /* read config */
733 if (res != 0) /* check result */
734 {
735 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
736
737 return 1; /* return error */
738 }
739 prev &= ~(7 << 4); /* clear settings */
740 prev |= mode << 4; /* set mode */
741 res = a_hdc2080_iic_write(handle, HDC2080_REG_CONF, &prev, 1); /* write config */
742 if (res != 0) /* check result */
743 {
744 handle->debug_print("hdc2080: write config failed.\n"); /* write config failed */
745
746 return 1; /* return error */
747 }
748
749 return 0; /* success return 0 */
750}
751
764{
765 uint8_t res;
766 uint8_t prev;
767
768 if (handle == NULL) /* check handle */
769 {
770 return 2; /* return error */
771 }
772 if (handle->inited != 1) /* check handle initialization */
773 {
774 return 3; /* return error */
775 }
776
777 res = a_hdc2080_iic_read(handle, HDC2080_REG_CONF, &prev, 1); /* read config */
778 if (res != 0) /* check result */
779 {
780 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
781
782 return 1; /* return error */
783 }
784 *mode = (hdc2080_auto_measurement_mode_t)((prev >> 4) & 0x07); /* get mode */
785
786 return 0; /* success return 0 */
787}
788
801{
802 uint8_t res;
803 uint8_t prev;
804
805 if (handle == NULL) /* check handle */
806 {
807 return 2; /* return error */
808 }
809 if (handle->inited != 1) /* check handle initialization */
810 {
811 return 3; /* return error */
812 }
813
814 res = a_hdc2080_iic_read(handle, HDC2080_REG_CONF, &prev, 1); /* read config */
815 if (res != 0) /* check result */
816 {
817 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
818
819 return 1; /* return error */
820 }
821 prev &= ~(1 << 3); /* clear settings */
822 prev |= enable << 3; /* set bool */
823 res = a_hdc2080_iic_write(handle, HDC2080_REG_CONF, &prev, 1); /* write config */
824 if (res != 0) /* check result */
825 {
826 handle->debug_print("hdc2080: write config failed.\n"); /* write config failed */
827
828 return 1; /* return error */
829 }
830
831 return 0; /* success return 0 */
832}
833
846{
847 uint8_t res;
848 uint8_t prev;
849
850 if (handle == NULL) /* check handle */
851 {
852 return 2; /* return error */
853 }
854 if (handle->inited != 1) /* check handle initialization */
855 {
856 return 3; /* return error */
857 }
858
859 res = a_hdc2080_iic_read(handle, HDC2080_REG_CONF, &prev, 1); /* read config */
860 if (res != 0) /* check result */
861 {
862 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
863
864 return 1; /* return error */
865 }
866 *enable = (hdc2080_bool_t)((prev >> 3) & 0x01); /* get bool */
867
868 return 0; /* success return 0 */
869}
870
883{
884 uint8_t res;
885 uint8_t prev;
886
887 if (handle == NULL) /* check handle */
888 {
889 return 2; /* return error */
890 }
891 if (handle->inited != 1) /* check handle initialization */
892 {
893 return 3; /* return error */
894 }
895
896 res = a_hdc2080_iic_read(handle, HDC2080_REG_CONF, &prev, 1); /* read config */
897 if (res != 0) /* check result */
898 {
899 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
900
901 return 1; /* return error */
902 }
903 prev &= ~(1 << 2); /* clear settings */
904 prev |= enable << 2; /* set bool */
905 res = a_hdc2080_iic_write(handle, HDC2080_REG_CONF, &prev, 1); /* write config */
906 if (res != 0) /* check result */
907 {
908 handle->debug_print("hdc2080: write config failed.\n"); /* write config failed */
909
910 return 1; /* return error */
911 }
912
913 return 0; /* success return 0 */
914}
915
928{
929 uint8_t res;
930 uint8_t prev;
931
932 if (handle == NULL) /* check handle */
933 {
934 return 2; /* return error */
935 }
936 if (handle->inited != 1) /* check handle initialization */
937 {
938 return 3; /* return error */
939 }
940
941 res = a_hdc2080_iic_read(handle, HDC2080_REG_CONF, &prev, 1); /* read config */
942 if (res != 0) /* check result */
943 {
944 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
945
946 return 1; /* return error */
947 }
948 *enable = (hdc2080_bool_t)((prev >> 2) & 0x01); /* get bool */
949
950 return 0; /* success return 0 */
951}
952
965{
966 uint8_t res;
967 uint8_t prev;
968
969 if (handle == NULL) /* check handle */
970 {
971 return 2; /* return error */
972 }
973 if (handle->inited != 1) /* check handle initialization */
974 {
975 return 3; /* return error */
976 }
977
978 res = a_hdc2080_iic_read(handle, HDC2080_REG_CONF, &prev, 1); /* read config */
979 if (res != 0) /* check result */
980 {
981 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
982
983 return 1; /* return error */
984 }
985 prev &= ~(1 << 1); /* clear settings */
986 prev |= polarity << 1; /* set bool */
987 res = a_hdc2080_iic_write(handle, HDC2080_REG_CONF, &prev, 1); /* write config */
988 if (res != 0) /* check result */
989 {
990 handle->debug_print("hdc2080: write config failed.\n"); /* write config failed */
991
992 return 1; /* return error */
993 }
994
995 return 0; /* success return 0 */
996}
997
1010{
1011 uint8_t res;
1012 uint8_t prev;
1013
1014 if (handle == NULL) /* check handle */
1015 {
1016 return 2; /* return error */
1017 }
1018 if (handle->inited != 1) /* check handle initialization */
1019 {
1020 return 3; /* return error */
1021 }
1022
1023 res = a_hdc2080_iic_read(handle, HDC2080_REG_CONF, &prev, 1); /* read config */
1024 if (res != 0) /* check result */
1025 {
1026 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
1027
1028 return 1; /* return error */
1029 }
1030 *polarity = (hdc2080_interrupt_polarity_t)((prev >> 1) & 0x01); /* get bool */
1031
1032 return 0; /* success return 0 */
1033}
1034
1047{
1048 uint8_t res;
1049 uint8_t prev;
1050
1051 if (handle == NULL) /* check handle */
1052 {
1053 return 2; /* return error */
1054 }
1055 if (handle->inited != 1) /* check handle initialization */
1056 {
1057 return 3; /* return error */
1058 }
1059
1060 res = a_hdc2080_iic_read(handle, HDC2080_REG_CONF, &prev, 1); /* read config */
1061 if (res != 0) /* check result */
1062 {
1063 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
1064
1065 return 1; /* return error */
1066 }
1067 prev &= ~(1 << 0); /* clear settings */
1068 prev |= mode << 0; /* set bool */
1069 res = a_hdc2080_iic_write(handle, HDC2080_REG_CONF, &prev, 1); /* write config */
1070 if (res != 0) /* check result */
1071 {
1072 handle->debug_print("hdc2080: write config failed.\n"); /* write config failed */
1073
1074 return 1; /* return error */
1075 }
1076
1077 return 0; /* success return 0 */
1078}
1079
1092{
1093 uint8_t res;
1094 uint8_t prev;
1095
1096 if (handle == NULL) /* check handle */
1097 {
1098 return 2; /* return error */
1099 }
1100 if (handle->inited != 1) /* check handle initialization */
1101 {
1102 return 3; /* return error */
1103 }
1104
1105 res = a_hdc2080_iic_read(handle, HDC2080_REG_CONF, &prev, 1); /* read config */
1106 if (res != 0) /* check result */
1107 {
1108 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
1109
1110 return 1; /* return error */
1111 }
1112 *mode = (hdc2080_interrupt_mode_t)((prev >> 0) & 0x01); /* get mode */
1113
1114 return 0; /* success return 0 */
1115}
1116
1129{
1130 uint8_t res;
1131 uint8_t prev;
1132
1133 if (handle == NULL) /* check handle */
1134 {
1135 return 2; /* return error */
1136 }
1137 if (handle->inited != 1) /* check handle initialization */
1138 {
1139 return 3; /* return error */
1140 }
1141
1142 prev = threshold; /* set threshold */
1143 res = a_hdc2080_iic_write(handle, HDC2080_REG_RH_THR_H, &prev, 1); /* write config */
1144 if (res != 0) /* check result */
1145 {
1146 handle->debug_print("hdc2080: write config failed.\n"); /* write config failed */
1147
1148 return 1; /* return error */
1149 }
1150
1151 return 0; /* success return 0 */
1152}
1153
1165uint8_t hdc2080_get_humidity_high_threshold(hdc2080_handle_t *handle, uint8_t *threshold)
1166{
1167 uint8_t res;
1168 uint8_t prev;
1169
1170 if (handle == NULL) /* check handle */
1171 {
1172 return 2; /* return error */
1173 }
1174 if (handle->inited != 1) /* check handle initialization */
1175 {
1176 return 3; /* return error */
1177 }
1178
1179 res = a_hdc2080_iic_read(handle, HDC2080_REG_RH_THR_H, &prev, 1); /* read config */
1180 if (res != 0) /* check result */
1181 {
1182 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
1183
1184 return 1; /* return error */
1185 }
1186 *threshold = prev; /* set threshold */
1187
1188 return 0; /* success return 0 */
1189}
1190
1202uint8_t hdc2080_set_humidity_low_threshold(hdc2080_handle_t *handle, uint8_t threshold)
1203{
1204 uint8_t res;
1205 uint8_t prev;
1206
1207 if (handle == NULL) /* check handle */
1208 {
1209 return 2; /* return error */
1210 }
1211 if (handle->inited != 1) /* check handle initialization */
1212 {
1213 return 3; /* return error */
1214 }
1215
1216 prev = threshold; /* set threshold */
1217 res = a_hdc2080_iic_write(handle, HDC2080_REG_RH_THR_L, &prev, 1); /* write config */
1218 if (res != 0) /* check result */
1219 {
1220 handle->debug_print("hdc2080: write config failed.\n"); /* write config failed */
1221
1222 return 1; /* return error */
1223 }
1224
1225 return 0; /* success return 0 */
1226}
1227
1239uint8_t hdc2080_get_humidity_low_threshold(hdc2080_handle_t *handle, uint8_t *threshold)
1240{
1241 uint8_t res;
1242 uint8_t prev;
1243
1244 if (handle == NULL) /* check handle */
1245 {
1246 return 2; /* return error */
1247 }
1248 if (handle->inited != 1) /* check handle initialization */
1249 {
1250 return 3; /* return error */
1251 }
1252
1253 res = a_hdc2080_iic_read(handle, HDC2080_REG_RH_THR_L, &prev, 1); /* read config */
1254 if (res != 0) /* check result */
1255 {
1256 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
1257
1258 return 1; /* return error */
1259 }
1260 *threshold = prev; /* set threshold */
1261
1262 return 0; /* success return 0 */
1263}
1264
1277{
1278 uint8_t res;
1279 uint8_t prev;
1280
1281 if (handle == NULL) /* check handle */
1282 {
1283 return 2; /* return error */
1284 }
1285 if (handle->inited != 1) /* check handle initialization */
1286 {
1287 return 3; /* return error */
1288 }
1289
1290 prev = threshold; /* set threshold */
1291 res = a_hdc2080_iic_write(handle, HDC2080_REG_TEMP_THR_H, &prev, 1); /* write config */
1292 if (res != 0) /* check result */
1293 {
1294 handle->debug_print("hdc2080: write config failed.\n"); /* write config failed */
1295
1296 return 1; /* return error */
1297 }
1298
1299 return 0; /* success return 0 */
1300}
1301
1314{
1315 uint8_t res;
1316 uint8_t prev;
1317
1318 if (handle == NULL) /* check handle */
1319 {
1320 return 2; /* return error */
1321 }
1322 if (handle->inited != 1) /* check handle initialization */
1323 {
1324 return 3; /* return error */
1325 }
1326
1327 res = a_hdc2080_iic_read(handle, HDC2080_REG_TEMP_THR_H, &prev, 1); /* read config */
1328 if (res != 0) /* check result */
1329 {
1330 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
1331
1332 return 1; /* return error */
1333 }
1334 *threshold = prev; /* set threshold */
1335
1336 return 0; /* success return 0 */
1337}
1338
1351{
1352 uint8_t res;
1353 uint8_t prev;
1354
1355 if (handle == NULL) /* check handle */
1356 {
1357 return 2; /* return error */
1358 }
1359 if (handle->inited != 1) /* check handle initialization */
1360 {
1361 return 3; /* return error */
1362 }
1363
1364 prev = threshold; /* set threshold */
1365 res = a_hdc2080_iic_write(handle, HDC2080_REG_TEMP_THR_L, &prev, 1); /* write config */
1366 if (res != 0) /* check result */
1367 {
1368 handle->debug_print("hdc2080: write config failed.\n"); /* write config failed */
1369
1370 return 1; /* return error */
1371 }
1372
1373 return 0; /* success return 0 */
1374}
1375
1388{
1389 uint8_t res;
1390 uint8_t prev;
1391
1392 if (handle == NULL) /* check handle */
1393 {
1394 return 2; /* return error */
1395 }
1396 if (handle->inited != 1) /* check handle initialization */
1397 {
1398 return 3; /* return error */
1399 }
1400
1401 res = a_hdc2080_iic_read(handle, HDC2080_REG_TEMP_THR_L, &prev, 1); /* read config */
1402 if (res != 0) /* check result */
1403 {
1404 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
1405
1406 return 1; /* return error */
1407 }
1408 *threshold = prev; /* set threshold */
1409
1410 return 0; /* success return 0 */
1411}
1412
1425{
1426 uint8_t res;
1427 uint8_t prev;
1428
1429 if (handle == NULL) /* check handle */
1430 {
1431 return 2; /* return error */
1432 }
1433 if (handle->inited != 1) /* check handle initialization */
1434 {
1435 return 3; /* return error */
1436 }
1437
1438 prev = (uint8_t)(offset); /* set offset */
1439 res = a_hdc2080_iic_write(handle, HDC2080_REG_HUM_OFFSET_ADJUST, &prev, 1); /* write config */
1440 if (res != 0) /* check result */
1441 {
1442 handle->debug_print("hdc2080: write config failed.\n"); /* write config failed */
1443
1444 return 1; /* return error */
1445 }
1446
1447 return 0; /* success return 0 */
1448}
1449
1462{
1463 uint8_t res;
1464 uint8_t prev;
1465
1466 if (handle == NULL) /* check handle */
1467 {
1468 return 2; /* return error */
1469 }
1470 if (handle->inited != 1) /* check handle initialization */
1471 {
1472 return 3; /* return error */
1473 }
1474
1475 res = a_hdc2080_iic_read(handle, HDC2080_REG_HUM_OFFSET_ADJUST, &prev, 1); /* read config */
1476 if (res != 0) /* check result */
1477 {
1478 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
1479
1480 return 1; /* return error */
1481 }
1482 *offset = (int8_t)(prev); /* set offset */
1483
1484 return 0; /* success return 0 */
1485}
1486
1499{
1500 uint8_t res;
1501 uint8_t prev;
1502
1503 if (handle == NULL) /* check handle */
1504 {
1505 return 2; /* return error */
1506 }
1507 if (handle->inited != 1) /* check handle initialization */
1508 {
1509 return 3; /* return error */
1510 }
1511
1512 prev = (uint8_t)(offset); /* set offset */
1513 res = a_hdc2080_iic_write(handle, HDC2080_REG_TEMP_OFFSET_ADJUST, &prev, 1); /* write config */
1514 if (res != 0) /* check result */
1515 {
1516 handle->debug_print("hdc2080: write config failed.\n"); /* write config failed */
1517
1518 return 1; /* return error */
1519 }
1520
1521 return 0; /* success return 0 */
1522}
1523
1536{
1537 uint8_t res;
1538 uint8_t prev;
1539
1540 if (handle == NULL) /* check handle */
1541 {
1542 return 2; /* return error */
1543 }
1544 if (handle->inited != 1) /* check handle initialization */
1545 {
1546 return 3; /* return error */
1547 }
1548
1549 res = a_hdc2080_iic_read(handle, HDC2080_REG_TEMP_OFFSET_ADJUST, &prev, 1); /* read config */
1550 if (res != 0) /* check result */
1551 {
1552 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
1553
1554 return 1; /* return error */
1555 }
1556 *offset = (int8_t)(prev); /* set offset */
1557
1558 return 0; /* success return 0 */
1559}
1560
1574{
1575 uint8_t res;
1576 uint8_t prev;
1577
1578 if (handle == NULL) /* check handle */
1579 {
1580 return 2; /* return error */
1581 }
1582 if (handle->inited != 1) /* check handle initialization */
1583 {
1584 return 3; /* return error */
1585 }
1586
1587 res = a_hdc2080_iic_read(handle, HDC2080_REG_INTERRUPT_ENABLE, &prev, 1); /* read config */
1588 if (res != 0) /* check result */
1589 {
1590 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
1591
1592 return 1; /* return error */
1593 }
1594 prev &= ~(1 << interrupt); /* clear settings */
1595 prev |= enable << interrupt; /* set bool */
1596 res = a_hdc2080_iic_write(handle, HDC2080_REG_INTERRUPT_ENABLE, &prev, 1); /* write config */
1597 if (res != 0) /* check result */
1598 {
1599 handle->debug_print("hdc2080: write config failed.\n"); /* write config failed */
1600
1601 return 1; /* return error */
1602 }
1603
1604 return 0; /* success return 0 */
1605}
1606
1620{
1621 uint8_t res;
1622 uint8_t prev;
1623
1624 if (handle == NULL) /* check handle */
1625 {
1626 return 2; /* return error */
1627 }
1628 if (handle->inited != 1) /* check handle initialization */
1629 {
1630 return 3; /* return error */
1631 }
1632
1633 res = a_hdc2080_iic_read(handle, HDC2080_REG_INTERRUPT_ENABLE, &prev, 1); /* read config */
1634 if (res != 0) /* check result */
1635 {
1636 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
1637
1638 return 1; /* return error */
1639 }
1640 *enable = (hdc2080_bool_t)((prev >> interrupt) & 0x01); /* get bool */
1641
1642 return 0; /* success return 0 */
1643}
1644
1656uint8_t hdc2080_set_humidity_max(hdc2080_handle_t *handle, uint8_t max)
1657{
1658 uint8_t res;
1659 uint8_t prev;
1660
1661 if (handle == NULL) /* check handle */
1662 {
1663 return 2; /* return error */
1664 }
1665 if (handle->inited != 1) /* check handle initialization */
1666 {
1667 return 3; /* return error */
1668 }
1669
1670 prev = max; /* set max */
1671 res = a_hdc2080_iic_write(handle, HDC2080_REG_HUMIDITY_MAX, &prev, 1); /* write config */
1672 if (res != 0) /* check result */
1673 {
1674 handle->debug_print("hdc2080: write config failed.\n"); /* write config failed */
1675
1676 return 1; /* return error */
1677 }
1678
1679 return 0; /* success return 0 */
1680}
1681
1693uint8_t hdc2080_get_humidity_max(hdc2080_handle_t *handle, uint8_t *max)
1694{
1695 uint8_t res;
1696 uint8_t prev;
1697
1698 if (handle == NULL) /* check handle */
1699 {
1700 return 2; /* return error */
1701 }
1702 if (handle->inited != 1) /* check handle initialization */
1703 {
1704 return 3; /* return error */
1705 }
1706
1707 res = a_hdc2080_iic_read(handle, HDC2080_REG_HUMIDITY_MAX, &prev, 1); /* read config */
1708 if (res != 0) /* check result */
1709 {
1710 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
1711
1712 return 1; /* return error */
1713 }
1714 *max = prev; /* get max */
1715
1716 return 0; /* success return 0 */
1717}
1718
1731{
1732 uint8_t res;
1733 uint8_t prev;
1734
1735 if (handle == NULL) /* check handle */
1736 {
1737 return 2; /* return error */
1738 }
1739 if (handle->inited != 1) /* check handle initialization */
1740 {
1741 return 3; /* return error */
1742 }
1743
1744 prev = max; /* set max */
1745 res = a_hdc2080_iic_write(handle, HDC2080_REG_TEMPERATURE_MAX, &prev, 1); /* write config */
1746 if (res != 0) /* check result */
1747 {
1748 handle->debug_print("hdc2080: write config failed.\n"); /* write config failed */
1749
1750 return 1; /* return error */
1751 }
1752
1753 return 0; /* success return 0 */
1754}
1755
1767uint8_t hdc2080_get_temperature_max(hdc2080_handle_t *handle, uint8_t *max)
1768{
1769 uint8_t res;
1770 uint8_t prev;
1771
1772 if (handle == NULL) /* check handle */
1773 {
1774 return 2; /* return error */
1775 }
1776 if (handle->inited != 1) /* check handle initialization */
1777 {
1778 return 3; /* return error */
1779 }
1780
1781 res = a_hdc2080_iic_read(handle, HDC2080_REG_TEMPERATURE_MAX, &prev, 1); /* read config */
1782 if (res != 0) /* check result */
1783 {
1784 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
1785
1786 return 1; /* return error */
1787 }
1788 *max = prev; /* get max */
1789
1790 return 0; /* success return 0 */
1791}
1792
1804uint8_t hdc2080_get_interrupt_status(hdc2080_handle_t *handle, uint8_t *status)
1805{
1806 uint8_t res;
1807 uint8_t prev;
1808
1809 if (handle == NULL) /* check handle */
1810 {
1811 return 2; /* return error */
1812 }
1813 if (handle->inited != 1) /* check handle initialization */
1814 {
1815 return 3; /* return error */
1816 }
1817
1818 res = a_hdc2080_iic_read(handle, HDC2080_REG_INTERRUPT_DRDY, &prev, 1); /* read config */
1819 if (res != 0) /* check result */
1820 {
1821 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
1822
1823 return 1; /* return error */
1824 }
1825 *status = prev; /* get status */
1826
1827 return 0; /* success return 0 */
1828}
1829
1841uint8_t hdc2080_humidity_convert_to_register(hdc2080_handle_t *handle, float percent, uint8_t *reg)
1842{
1843 if (handle == NULL) /* check handle */
1844 {
1845 return 2; /* return error */
1846 }
1847 if (handle->inited != 1) /* check handle initialization */
1848 {
1849 return 3; /* return error */
1850 }
1851
1852 *reg = (uint8_t)(percent / 100.0f * (float)(256.0f)); /* convert real data to register data */
1853
1854 return 0; /* success return 0 */
1855}
1856
1868uint8_t hdc2080_humidity_convert_to_data(hdc2080_handle_t *handle, uint8_t reg, float *percent)
1869{
1870 if (handle == NULL) /* check handle */
1871 {
1872 return 2; /* return error */
1873 }
1874 if (handle->inited != 1) /* check handle initialization */
1875 {
1876 return 3; /* return error */
1877 }
1878
1879 *percent = (float)(reg) / 256.0f * 100.0f; /* convert raw data to real data */
1880
1881 return 0; /* success return 0 */
1882}
1883
1895uint8_t hdc2080_temperature_convert_to_register(hdc2080_handle_t *handle, float deg, uint8_t *reg)
1896{
1897 if (handle == NULL) /* check handle */
1898 {
1899 return 2; /* return error */
1900 }
1901 if (handle->inited != 1) /* check handle initialization */
1902 {
1903 return 3; /* return error */
1904 }
1905
1906 *reg = (uint8_t)((deg + 40.5f) / 165.0f * (float)(256.0f)); /* convert real data to register data */
1907
1908 return 0; /* success return 0 */
1909}
1910
1922uint8_t hdc2080_temperature_convert_to_data(hdc2080_handle_t *handle, uint8_t reg, float *deg)
1923{
1924 if (handle == NULL) /* check handle */
1925 {
1926 return 2; /* return error */
1927 }
1928 if (handle->inited != 1) /* check handle initialization */
1929 {
1930 return 3; /* return error */
1931 }
1932
1933 *deg = (float)(reg) / 256.0f * 165.0f - 40.5f; /* convert raw data to real data */
1934
1935 return 0; /* success return 0 */
1936}
1937
1949uint8_t hdc2080_humidity_offset_convert_to_register(hdc2080_handle_t *handle, float percent, int8_t *reg)
1950{
1951 if (handle == NULL) /* check handle */
1952 {
1953 return 2; /* return error */
1954 }
1955 if (handle->inited != 1) /* check handle initialization */
1956 {
1957 return 3; /* return error */
1958 }
1959
1960 *reg = (int8_t)(percent / 0.2f); /* convert real data to register data */
1961
1962 return 0; /* success return 0 */
1963}
1964
1976uint8_t hdc2080_humidity_offset_convert_to_data(hdc2080_handle_t *handle, int8_t reg, float *percent)
1977{
1978 if (handle == NULL) /* check handle */
1979 {
1980 return 2; /* return error */
1981 }
1982 if (handle->inited != 1) /* check handle initialization */
1983 {
1984 return 3; /* return error */
1985 }
1986
1987 *percent = (float)(reg) * 0.2f; /* convert raw data to real data */
1988
1989 return 0; /* success return 0 */
1990}
1991
2004{
2005 if (handle == NULL) /* check handle */
2006 {
2007 return 2; /* return error */
2008 }
2009 if (handle->inited != 1) /* check handle initialization */
2010 {
2011 return 3; /* return error */
2012 }
2013
2014 *reg = (int8_t)(deg / 0.16f); /* convert real data to register data */
2015
2016 return 0; /* success return 0 */
2017}
2018
2030uint8_t hdc2080_temperature_offset_convert_to_data(hdc2080_handle_t *handle, int8_t reg, float *deg)
2031{
2032 if (handle == NULL) /* check handle */
2033 {
2034 return 2; /* return error */
2035 }
2036 if (handle->inited != 1) /* check handle initialization */
2037 {
2038 return 3; /* return error */
2039 }
2040
2041 *deg = (float)(reg) * 0.16f; /* convert raw data to real data */
2042
2043 return 0; /* success return 0 */
2044}
2045
2060uint8_t hdc2080_read_temperature_humidity(hdc2080_handle_t *handle, uint16_t *temperature_raw, float *temperature_s,
2061 uint16_t *humidity_raw, float *humidity_s)
2062{
2063 uint8_t res;
2064 uint8_t buf[2];
2065
2066 if (handle == NULL) /* check handle */
2067 {
2068 return 2; /* return error */
2069 }
2070 if (handle->inited != 1) /* check handle initialization */
2071 {
2072 return 3; /* return error */
2073 }
2074
2075 res = a_hdc2080_iic_read(handle, HDC2080_REG_TEMPERATURE_LOW, buf, 2); /* read temperature */
2076 if (res != 0) /* check result */
2077 {
2078 handle->debug_print("hdc2080: read temperature failed.\n"); /* read temperature failed */
2079
2080 return 1; /* return error */
2081 }
2082 *temperature_raw = buf[0] | (uint16_t)(buf[1]) << 8; /* get temperature */
2083 *temperature_s = (float)(*temperature_raw) / 65536.0f * 165.0f - 40.5f; /* convert temperature */
2084 res = a_hdc2080_iic_read(handle, HDC2080_REG_HUMIDITY_LOW, buf, 2); /* read humidity */
2085 if (res != 0) /* check result */
2086 {
2087 handle->debug_print("hdc2080: read humidity failed.\n"); /* read humidity failed */
2088
2089 return 1; /* return error */
2090 }
2091 *humidity_raw = buf[0] | (uint16_t)(buf[1]) << 8; /* get humidity */
2092 *humidity_s = (float)(*humidity_raw) / 65536.0f * 100.0f; /* convert humidity */
2093
2094 return 0; /* success return 0 */
2095}
2096
2109uint8_t hdc2080_read_temperature(hdc2080_handle_t *handle, uint16_t *temperature_raw, float *temperature_s)
2110{
2111 uint8_t res;
2112 uint8_t buf[2];
2113
2114 if (handle == NULL) /* check handle */
2115 {
2116 return 2; /* return error */
2117 }
2118 if (handle->inited != 1) /* check handle initialization */
2119 {
2120 return 3; /* return error */
2121 }
2122
2123 res = a_hdc2080_iic_read(handle, HDC2080_REG_TEMPERATURE_LOW, buf, 2); /* read temperature */
2124 if (res != 0) /* check result */
2125 {
2126 handle->debug_print("hdc2080: read temperature failed.\n"); /* read temperature failed */
2127
2128 return 1; /* return error */
2129 }
2130 *temperature_raw = buf[0] | (uint16_t)(buf[1]) << 8; /* get temperature */
2131 *temperature_s = (float)(*temperature_raw) / 65536.0f * 165.0f - 40.5f; /* convert temperature */
2132
2133 return 0; /* success return 0 */
2134}
2135
2148uint8_t hdc2080_read_humidity(hdc2080_handle_t *handle, uint16_t *humidity_raw, float *humidity_s)
2149{
2150 uint8_t res;
2151 uint8_t buf[2];
2152
2153 if (handle == NULL) /* check handle */
2154 {
2155 return 2; /* return error */
2156 }
2157 if (handle->inited != 1) /* check handle initialization */
2158 {
2159 return 3; /* return error */
2160 }
2161
2162 res = a_hdc2080_iic_read(handle, HDC2080_REG_HUMIDITY_LOW, buf, 2); /* read humidity */
2163 if (res != 0) /* check result */
2164 {
2165 handle->debug_print("hdc2080: read humidity failed.\n"); /* read humidity failed */
2166
2167 return 1; /* return error */
2168 }
2169 *humidity_raw = buf[0] | (uint16_t)(buf[1]) << 8; /* get humidity */
2170 *humidity_s = (float)(*humidity_raw) / 65536.0f * 100.0f; /* convert humidity */
2171
2172 return 0; /* success return 0 */
2173}
2174
2187{
2188 uint8_t res;
2189 uint8_t prev;
2190 uint32_t i;
2191 uint32_t timeout = 500;
2192
2193 if (handle == NULL) /* check handle */
2194 {
2195 return 2; /* return error */
2196 }
2197 if (handle->inited != 1) /* check handle initialization */
2198 {
2199 return 3; /* return error */
2200 }
2201
2202 res = a_hdc2080_iic_read(handle, HDC2080_REG_MEASUREMENT, &prev, 1); /* read config */
2203 if (res != 0) /* check result */
2204 {
2205 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
2206
2207 return 1; /* return error */
2208 }
2209 prev &= ~(1 << 0); /* clear settings */
2210 prev |= 1 << 0; /* set bool */
2211 res = a_hdc2080_iic_write(handle, HDC2080_REG_MEASUREMENT, &prev, 1); /* write config */
2212 if (res != 0) /* check result */
2213 {
2214 handle->debug_print("hdc2080: write config failed.\n"); /* write config failed */
2215
2216 return 1; /* return error */
2217 }
2218 for (i = 0; i < timeout; i++) /* wait */
2219 {
2220 res = a_hdc2080_iic_read(handle, HDC2080_REG_MEASUREMENT, &prev, 1); /* read config */
2221 if (res != 0) /* check result */
2222 {
2223 handle->debug_print("hdc2080: read config failed.\n"); /* read config failed */
2224
2225 return 1; /* return error */
2226 }
2227 if (((prev >> 0) & 0x01) == 0) /* check flag */
2228 {
2229 break; /* break */
2230 }
2231 handle->delay_ms(10); /* delay 10ms */
2232 }
2233 if (i >= timeout) /* check timeout */
2234 {
2235 handle->debug_print("hdc2080: read timeout.\n"); /* read timeout */
2236
2237 return 4; /* return error */
2238 }
2239
2240 return 0; /* success return 0 */
2241}
2242
2256uint8_t hdc2080_set_reg(hdc2080_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
2257{
2258 if (handle == NULL) /* check handle */
2259 {
2260 return 2; /* return error */
2261 }
2262 if (handle->inited != 1) /* check handle initialization */
2263 {
2264 return 3; /* return error */
2265 }
2266
2267 if (a_hdc2080_iic_write(handle, reg, buf, len) != 0) /* write data */
2268 {
2269 return 1; /* return error */
2270 }
2271 else
2272 {
2273 return 0; /* success return 0 */
2274 }
2275}
2276
2290uint8_t hdc2080_get_reg(hdc2080_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
2291{
2292 if (handle == NULL) /* check handle */
2293 {
2294 return 2; /* return error */
2295 }
2296 if (handle->inited != 1) /* check handle initialization */
2297 {
2298 return 3; /* return error */
2299 }
2300
2301 if (a_hdc2080_iic_read(handle, reg, buf, len) != 0) /* read data */
2302 {
2303 return 1; /* return error */
2304 }
2305 else
2306 {
2307 return 0; /* success return 0 */
2308 }
2309}
2310
2320{
2321 if (info == NULL) /* check handle */
2322 {
2323 return 2; /* return error */
2324 }
2325
2326 memset(info, 0, sizeof(hdc2080_info_t)); /* initialize hdc2080 info structure */
2327 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
2328 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
2329 strncpy(info->interface, "IIC", 8); /* copy interface name */
2330 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
2331 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
2332 info->max_current_ma = MAX_CURRENT; /* set maximum current */
2333 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
2334 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
2335 info->driver_version = DRIVER_VERSION; /* set driver version */
2336
2337 return 0; /* success return 0 */
2338}
#define HDC2080_REG_INTERRUPT_ENABLE
#define HDC2080_REG_HUMIDITY_MAX
#define MAX_CURRENT
#define HDC2080_REG_INTERRUPT_DRDY
#define HDC2080_REG_RH_THR_L
#define HDC2080_REG_HUMIDITY_LOW
#define HDC2080_REG_TEMP_THR_H
#define HDC2080_REG_TEMPERATURE_LOW
chip register definition
#define SUPPLY_VOLTAGE_MAX
#define HDC2080_REG_TEMP_THR_L
#define HDC2080_REG_DEVICE_ID_LOW
#define TEMPERATURE_MAX
#define HDC2080_REG_MEASUREMENT
#define HDC2080_REG_HUM_OFFSET_ADJUST
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define HDC2080_REG_RH_THR_H
#define HDC2080_REG_TEMP_OFFSET_ADJUST
#define HDC2080_REG_CONF
#define HDC2080_REG_TEMPERATURE_MAX
#define CHIP_NAME
chip information definition
#define DRIVER_VERSION
#define HDC2080_REG_MANUFACTURER_ID_LOW
driver hdc2080 header file
uint8_t hdc2080_set_measurement(hdc2080_handle_t *handle, hdc2080_bool_t enable)
enable or disable measurement
uint8_t hdc2080_init(hdc2080_handle_t *handle)
initialize the chip
uint8_t hdc2080_set_temperature_offset_adjustment(hdc2080_handle_t *handle, int8_t offset)
set temperature offset adjustment
uint8_t hdc2080_set_temperature_low_threshold(hdc2080_handle_t *handle, uint8_t threshold)
set temperature low threshold
uint8_t hdc2080_get_addr_pin(hdc2080_handle_t *handle, hdc2080_address_t *addr_pin)
get the iic address pin
uint8_t hdc2080_set_auto_measurement_mode(hdc2080_handle_t *handle, hdc2080_auto_measurement_mode_t mode)
set auto measurement mode
uint8_t hdc2080_get_temperature_low_threshold(hdc2080_handle_t *handle, uint8_t *threshold)
get temperature low threshold
struct hdc2080_handle_s hdc2080_handle_t
hdc2080 handle structure definition
uint8_t hdc2080_set_humidity_resolution(hdc2080_handle_t *handle, hdc2080_resolution_t resolution)
set humidity resolution
uint8_t hdc2080_read_temperature_humidity(hdc2080_handle_t *handle, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s)
read the temperature and humidity data
uint8_t hdc2080_get_humidity_low_threshold(hdc2080_handle_t *handle, uint8_t *threshold)
get humidity low threshold
uint8_t hdc2080_soft_reset(hdc2080_handle_t *handle)
soft reset
uint8_t hdc2080_deinit(hdc2080_handle_t *handle)
close the chip
uint8_t hdc2080_humidity_offset_convert_to_register(hdc2080_handle_t *handle, float percent, int8_t *reg)
convert the humidity offset to the register raw data
uint8_t hdc2080_set_temperature_resolution(hdc2080_handle_t *handle, hdc2080_resolution_t resolution)
set temperature resolution
uint8_t hdc2080_temperature_offset_convert_to_register(hdc2080_handle_t *handle, float deg, int8_t *reg)
convert the temperature offset to the register raw data
uint8_t hdc2080_temperature_convert_to_data(hdc2080_handle_t *handle, uint8_t reg, float *deg)
convert the register raw data to the temperature
uint8_t hdc2080_humidity_convert_to_data(hdc2080_handle_t *handle, uint8_t reg, float *percent)
convert the register raw data to the humidity
uint8_t hdc2080_set_interrupt_pin(hdc2080_handle_t *handle, hdc2080_bool_t enable)
enable or disable interrupt pin
uint8_t hdc2080_temperature_offset_convert_to_data(hdc2080_handle_t *handle, int8_t reg, float *deg)
convert the register raw data to the temperature offset
uint8_t hdc2080_get_interrupt_pin(hdc2080_handle_t *handle, hdc2080_bool_t *enable)
get interrupt pin status
uint8_t hdc2080_get_heater(hdc2080_handle_t *handle, hdc2080_bool_t *enable)
get heater status
uint8_t hdc2080_set_humidity_low_threshold(hdc2080_handle_t *handle, uint8_t threshold)
set humidity low threshold
uint8_t hdc2080_get_temperature_offset_adjustment(hdc2080_handle_t *handle, int8_t *offset)
get temperature offset adjustment
uint8_t hdc2080_get_humidity_max(hdc2080_handle_t *handle, uint8_t *max)
get humidity max
uint8_t hdc2080_set_addr_pin(hdc2080_handle_t *handle, hdc2080_address_t addr_pin)
set the iic address pin
hdc2080_bool_t
hdc2080 bool enumeration definition
uint8_t hdc2080_get_mode(hdc2080_handle_t *handle, hdc2080_mode_t *mode)
get the chip mode
uint8_t hdc2080_get_measurement(hdc2080_handle_t *handle, hdc2080_bool_t *enable)
get measurement status
hdc2080_resolution_t
hdc2080 resolution enumeration definition
uint8_t hdc2080_get_interrupt_polarity(hdc2080_handle_t *handle, hdc2080_interrupt_polarity_t *polarity)
get interrupt polarity
uint8_t hdc2080_set_mode(hdc2080_handle_t *handle, hdc2080_mode_t mode)
set the chip mode
uint8_t hdc2080_set_humidity_high_threshold(hdc2080_handle_t *handle, uint8_t threshold)
set humidity high threshold
hdc2080_auto_measurement_mode_t
hdc2080 auto measurement mode enumeration definition
hdc2080_interrupt_polarity_t
hdc2080 interrupt polarity enumeration definition
hdc2080_interrupt_mode_t
hdc2080 interrupt mode enumeration definition
uint8_t hdc2080_set_humidity_max(hdc2080_handle_t *handle, uint8_t max)
set humidity max
uint8_t hdc2080_get_humidity_offset_adjustment(hdc2080_handle_t *handle, int8_t *offset)
get humidity offset adjustment
hdc2080_interrupt_t
hdc2080 interrupt enumeration definition
uint8_t hdc2080_get_temperature_high_threshold(hdc2080_handle_t *handle, uint8_t *threshold)
get temperature high threshold
hdc2080_mode_t
hdc2080 mode enumeration definition
uint8_t hdc2080_get_auto_measurement_mode(hdc2080_handle_t *handle, hdc2080_auto_measurement_mode_t *mode)
get auto measurement mode
uint8_t hdc2080_set_interrupt_polarity(hdc2080_handle_t *handle, hdc2080_interrupt_polarity_t polarity)
set interrupt polarity
uint8_t hdc2080_get_interrupt_mode(hdc2080_handle_t *handle, hdc2080_interrupt_mode_t *mode)
get interrupt mode
uint8_t hdc2080_set_interrupt_mode(hdc2080_handle_t *handle, hdc2080_interrupt_mode_t mode)
set interrupt mode
struct hdc2080_info_s hdc2080_info_t
hdc2080 information structure definition
uint8_t hdc2080_set_humidity_offset_adjustment(hdc2080_handle_t *handle, int8_t offset)
set humidity offset adjustment
uint8_t hdc2080_set_heater(hdc2080_handle_t *handle, hdc2080_bool_t enable)
enable or disable heater
uint8_t hdc2080_humidity_convert_to_register(hdc2080_handle_t *handle, float percent, uint8_t *reg)
convert the humidity to the register raw data
uint8_t hdc2080_info(hdc2080_info_t *info)
get chip's information
uint8_t hdc2080_get_temperature_max(hdc2080_handle_t *handle, uint8_t *max)
get temperature max
uint8_t hdc2080_set_interrupt(hdc2080_handle_t *handle, hdc2080_interrupt_t interrupt, hdc2080_bool_t enable)
enable or disable interrupt
uint8_t hdc2080_set_temperature_max(hdc2080_handle_t *handle, uint8_t max)
set temperature max
uint8_t hdc2080_get_humidity_resolution(hdc2080_handle_t *handle, hdc2080_resolution_t *resolution)
get humidity resolution
uint8_t hdc2080_temperature_convert_to_register(hdc2080_handle_t *handle, float deg, uint8_t *reg)
convert the temperature to the register raw data
uint8_t hdc2080_get_interrupt_status(hdc2080_handle_t *handle, uint8_t *status)
get interrupt status
uint8_t hdc2080_read_humidity(hdc2080_handle_t *handle, uint16_t *humidity_raw, float *humidity_s)
read the humidity data
uint8_t hdc2080_set_temperature_high_threshold(hdc2080_handle_t *handle, uint8_t threshold)
set temperature high threshold
uint8_t hdc2080_get_humidity_high_threshold(hdc2080_handle_t *handle, uint8_t *threshold)
get humidity high threshold
uint8_t hdc2080_humidity_offset_convert_to_data(hdc2080_handle_t *handle, int8_t reg, float *percent)
convert the register raw data to the humidity offset
uint8_t hdc2080_read_poll(hdc2080_handle_t *handle)
read poll
uint8_t hdc2080_get_temperature_resolution(hdc2080_handle_t *handle, hdc2080_resolution_t *resolution)
get temperature resolution
uint8_t hdc2080_get_interrupt(hdc2080_handle_t *handle, hdc2080_interrupt_t interrupt, hdc2080_bool_t *enable)
get interrupt status
uint8_t hdc2080_read_temperature(hdc2080_handle_t *handle, uint16_t *temperature_raw, float *temperature_s)
read the temperature
hdc2080_address_t
hdc2080 address enumeration definition
uint8_t hdc2080_get_reg(hdc2080_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get chip register
uint8_t hdc2080_set_reg(hdc2080_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set chip register
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
uint32_t driver_version
char manufacturer_name[32]