LibDriver ENS160
Loading...
Searching...
No Matches
driver_ens160.c
Go to the documentation of this file.
1
36
37#include "driver_ens160.h"
38#include <math.h>
39
43#define CHIP_NAME "ScioSense ENS160"
44#define MANUFACTURER_NAME "ScioSense"
45#define SUPPLY_VOLTAGE_MIN 1.71f
46#define SUPPLY_VOLTAGE_MAX 1.98f
47#define MAX_CURRENT 79.0f
48#define TEMPERATURE_MIN -40.0f
49#define TEMPERATURE_MAX 85.0f
50#define DRIVER_VERSION 1000
51
55#define ENS160_REG_PART_ID 0x00
56#define ENS160_REG_OPMODE 0x10
57#define ENS160_REG_CONFIG 0x11
58#define ENS160_REG_COMMAND 0x12
59#define ENS160_REG_TEMP_IN 0x13
60#define ENS160_REG_RH_IN 0x15
61#define ENS160_REG_DEVICE_STATUS 0x20
62#define ENS160_REG_DATA_AQI 0x21
63#define ENS160_REG_DATA_TVOC 0x22
64#define ENS160_REG_DATA_ECO2 0x24
65#define ENS160_REG_DATA_ETOH 0x22
66#define ENS160_REG_DATA_T 0x30
67#define ENS160_REG_DATA_RH 0x32
68#define ENS160_REG_DATA_MISR 0x38
69#define ENS160_REG_GPR_WRITE 0x40
70#define ENS160_REG_GPR_READ 0x48
71
83static uint8_t a_ens160_iic_spi_read(ens160_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
84{
85 if (handle->iic_spi == ENS160_INTERFACE_IIC) /* iic interface */
86 {
87 if (handle->iic_read(handle->iic_addr, reg, buf, len) != 0) /* read data */
88 {
89 return 1; /* return error */
90 }
91
92 return 0; /* success return 0 */
93 }
94 else /* spi interface */
95 {
96 uint8_t reg_input;
97
98 reg_input = reg << 1; /* left shift */
99 reg_input |= 1 << 0; /* flag read */
100 if (handle->spi_read(reg_input, buf, len) != 0) /* read data */
101 {
102 return 1; /* return error */
103 }
104
105 return 0; /* success return 0 */
106 }
107}
108
120static uint8_t a_ens160_iic_spi_write(ens160_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
121{
122 if (handle->iic_spi == ENS160_INTERFACE_IIC) /* iic interface */
123 {
124 if (handle->iic_write(handle->iic_addr, reg, buf, len) != 0) /* write data */
125 {
126 return 1; /* return error */
127 }
128
129 return 0; /* success return 0 */
130 }
131 else /* spi interface */
132 {
133 uint8_t reg_index;
134 uint8_t reg_input;
135 uint16_t i;
136
137 reg_index = reg; /* init reg index */
138 for (i = 0; i < len; i++) /* write all */
139 {
140 reg_input = reg_index << 1; /* left shift */
141 reg_input &= ~(1 << 0); /* flag write */
142
143 if (handle->spi_write(reg_input, &buf[i], 1) != 0) /* write data */
144 {
145 return 1; /* return error */
146 }
147 reg_index++; /* index++ */
148 }
149
150 return 0; /* success return 0 */
151 }
152}
153
164{
165 if (handle == NULL) /* check handle */
166 {
167 return 2; /* return error */
168 }
169
170 handle->iic_spi = (uint8_t)interface; /* set interface */
171
172 return 0; /* success return 0 */
173}
174
185{
186 if (handle == NULL) /* check handle */
187 {
188 return 2; /* return error */
189 }
190
191 *interface = (ens160_interface_t)(handle->iic_spi); /* get interface */
192
193 return 0; /* success return 0 */
194}
195
206{
207 if (handle == NULL) /* check handle */
208 {
209 return 2; /* return error */
210 }
211
212 handle->iic_addr = (uint8_t)addr_pin; /* set pin */
213
214 return 0; /* success return 0 */
215}
216
227{
228 if (handle == NULL) /* check handle */
229 {
230 return 2; /* return error */
231 }
232
233 *addr_pin = (ens160_address_t)(handle->iic_addr); /* get pin */
234
235 return 0; /* success return 0 */
236}
237
250{
251 uint8_t res;
252 uint8_t prev;
253
254 if (handle == NULL) /* check handle */
255 {
256 return 2; /* return error */
257 }
258 if (handle->inited != 1) /* check handle initialization */
259 {
260 return 3; /* return error */
261 }
262
263 prev = (uint8_t)mode; /* set mode */
264 res = a_ens160_iic_spi_write(handle, ENS160_REG_OPMODE, &prev, 1); /* write config */
265 if (res != 0) /* check result */
266 {
267 handle->debug_print("ens160: set mode failed.\n"); /* set mode failed */
268
269 return 1; /* return error */
270 }
271 handle->delay_ms(10); /* delay 10ms */
272
273 return 0; /* success return 0 */
274}
275
288{
289 uint8_t res;
290 uint8_t prev;
291
292 if (handle == NULL) /* check handle */
293 {
294 return 2; /* return error */
295 }
296 if (handle->inited != 1) /* check handle initialization */
297 {
298 return 3; /* return error */
299 }
300
301 res = a_ens160_iic_spi_read(handle, ENS160_REG_OPMODE, &prev, 1); /* read config */
302 if (res != 0) /* check result */
303 {
304 handle->debug_print("ens160: get mode failed.\n"); /* get mode failed */
305
306 return 1; /* return error */
307 }
308 *mode = (ens160_mode_t)(prev); /* set mode */
309
310 return 0; /* success return 0 */
311}
312
324{
325 uint8_t res;
326 uint8_t prev;
327
328 if (handle == NULL) /* check handle */
329 {
330 return 2; /* return error */
331 }
332 if (handle->inited != 1) /* check handle initialization */
333 {
334 return 3; /* return error */
335 }
336
337 prev = (uint8_t)0xF0; /* set reset */
338 res = a_ens160_iic_spi_write(handle, ENS160_REG_OPMODE, &prev, 1); /* write config */
339 if (res != 0) /* check result */
340 {
341 handle->debug_print("ens160: set mode failed.\n"); /* set mode failed */
342
343 return 1; /* return error */
344 }
345 handle->delay_ms(100); /* delay 100ms */
346
347 return 0; /* success return 0 */
348}
349
362{
363 uint8_t res;
364 uint8_t prev;
365
366 if (handle == NULL) /* check handle */
367 {
368 return 2; /* return error */
369 }
370 if (handle->inited != 1) /* check handle initialization */
371 {
372 return 3; /* return error */
373 }
374
375 res = a_ens160_iic_spi_read(handle, ENS160_REG_CONFIG, &prev, 1); /* read config */
376 if (res != 0) /* check result */
377 {
378 handle->debug_print("ens160: get config failed.\n"); /* get config failed */
379
380 return 1; /* return error */
381 }
382 prev &= ~(1 << 6); /* clear settings */
383 prev |= polarity << 6; /* set polarity */
384 res = a_ens160_iic_spi_write(handle, ENS160_REG_CONFIG, &prev, 1); /* write config */
385 if (res != 0) /* check result */
386 {
387 handle->debug_print("ens160: set config failed.\n"); /* set config failed */
388
389 return 1; /* return error */
390 }
391 handle->delay_ms(10); /* delay 10ms */
392
393 return 0; /* success return 0 */
394}
395
408{
409 uint8_t res;
410 uint8_t prev;
411
412 if (handle == NULL) /* check handle */
413 {
414 return 2; /* return error */
415 }
416 if (handle->inited != 1) /* check handle initialization */
417 {
418 return 3; /* return error */
419 }
420
421 res = a_ens160_iic_spi_read(handle, ENS160_REG_CONFIG, &prev, 1); /* read config */
422 if (res != 0) /* check result */
423 {
424 handle->debug_print("ens160: get config failed.\n"); /* get config failed */
425
426 return 1; /* return error */
427 }
428 *polarity = (ens160_pin_polarity_t)((prev >> 6) & 0x01); /* set polarity */
429
430 return 0; /* success return 0 */
431}
432
445{
446 uint8_t res;
447 uint8_t prev;
448
449 if (handle == NULL) /* check handle */
450 {
451 return 2; /* return error */
452 }
453 if (handle->inited != 1) /* check handle initialization */
454 {
455 return 3; /* return error */
456 }
457
458 res = a_ens160_iic_spi_read(handle, ENS160_REG_CONFIG, &prev, 1); /* read config */
459 if (res != 0) /* check result */
460 {
461 handle->debug_print("ens160: get config failed.\n"); /* get config failed */
462
463 return 1; /* return error */
464 }
465 prev &= ~(1 << 5); /* clear settings */
466 prev |= drive << 5; /* set drive */
467 res = a_ens160_iic_spi_write(handle, ENS160_REG_CONFIG, &prev, 1); /* write config */
468 if (res != 0) /* check result */
469 {
470 handle->debug_print("ens160: set config failed.\n"); /* set config failed */
471
472 return 1; /* return error */
473 }
474 handle->delay_ms(10); /* delay 10ms */
475
476 return 0; /* success return 0 */
477}
478
491{
492 uint8_t res;
493 uint8_t prev;
494
495 if (handle == NULL) /* check handle */
496 {
497 return 2; /* return error */
498 }
499 if (handle->inited != 1) /* check handle initialization */
500 {
501 return 3; /* return error */
502 }
503
504 res = a_ens160_iic_spi_read(handle, ENS160_REG_CONFIG, &prev, 1); /* read config */
505 if (res != 0) /* check result */
506 {
507 handle->debug_print("ens160: get config failed.\n"); /* get config failed */
508
509 return 1; /* return error */
510 }
511 *drive = (ens160_pin_drive_t)((prev >> 5) & 0x01); /* set drive */
512
513 return 0; /* success return 0 */
514}
515
528{
529 uint8_t res;
530 uint8_t prev;
531
532 if (handle == NULL) /* check handle */
533 {
534 return 2; /* return error */
535 }
536 if (handle->inited != 1) /* check handle initialization */
537 {
538 return 3; /* return error */
539 }
540
541 res = a_ens160_iic_spi_read(handle, ENS160_REG_CONFIG, &prev, 1); /* read config */
542 if (res != 0) /* check result */
543 {
544 handle->debug_print("ens160: get config failed.\n"); /* get config failed */
545
546 return 1; /* return error */
547 }
548 prev &= ~(1 << 3); /* clear settings */
549 prev |= enable << 3; /* set bool */
550 res = a_ens160_iic_spi_write(handle, ENS160_REG_CONFIG, &prev, 1); /* write config */
551 if (res != 0) /* check result */
552 {
553 handle->debug_print("ens160: set config failed.\n"); /* set config failed */
554
555 return 1; /* return error */
556 }
557 handle->delay_ms(10); /* delay 10ms */
558
559 return 0; /* success return 0 */
560}
561
574{
575 uint8_t res;
576 uint8_t prev;
577
578 if (handle == NULL) /* check handle */
579 {
580 return 2; /* return error */
581 }
582 if (handle->inited != 1) /* check handle initialization */
583 {
584 return 3; /* return error */
585 }
586
587 res = a_ens160_iic_spi_read(handle, ENS160_REG_CONFIG, &prev, 1); /* read config */
588 if (res != 0) /* check result */
589 {
590 handle->debug_print("ens160: get config failed.\n"); /* get config failed */
591
592 return 1; /* return error */
593 }
594 *enable = (ens160_bool_t)((prev >> 3) & 0x01); /* set bool */
595
596 return 0; /* success return 0 */
597}
598
611{
612 uint8_t res;
613 uint8_t prev;
614
615 if (handle == NULL) /* check handle */
616 {
617 return 2; /* return error */
618 }
619 if (handle->inited != 1) /* check handle initialization */
620 {
621 return 3; /* return error */
622 }
623
624 res = a_ens160_iic_spi_read(handle, ENS160_REG_CONFIG, &prev, 1); /* read config */
625 if (res != 0) /* check result */
626 {
627 handle->debug_print("ens160: get config failed.\n"); /* get config failed */
628
629 return 1; /* return error */
630 }
631 prev &= ~(1 << 1); /* clear settings */
632 prev |= enable << 1; /* set bool */
633 res = a_ens160_iic_spi_write(handle, ENS160_REG_CONFIG, &prev, 1); /* write config */
634 if (res != 0) /* check result */
635 {
636 handle->debug_print("ens160: set config failed.\n"); /* set config failed */
637
638 return 1; /* return error */
639 }
640 handle->delay_ms(10); /* delay 10ms */
641
642 return 0; /* success return 0 */
643}
644
657{
658 uint8_t res;
659 uint8_t prev;
660
661 if (handle == NULL) /* check handle */
662 {
663 return 2; /* return error */
664 }
665 if (handle->inited != 1) /* check handle initialization */
666 {
667 return 3; /* return error */
668 }
669
670 res = a_ens160_iic_spi_read(handle, ENS160_REG_CONFIG, &prev, 1); /* read config */
671 if (res != 0) /* check result */
672 {
673 handle->debug_print("ens160: get config failed.\n"); /* get config failed */
674
675 return 1; /* return error */
676 }
677 *enable = (ens160_bool_t)((prev >> 1) & 0x01); /* set bool */
678
679 return 0; /* success return 0 */
680}
681
694{
695 uint8_t res;
696 uint8_t prev;
697
698 if (handle == NULL) /* check handle */
699 {
700 return 2; /* return error */
701 }
702 if (handle->inited != 1) /* check handle initialization */
703 {
704 return 3; /* return error */
705 }
706
707 res = a_ens160_iic_spi_read(handle, ENS160_REG_CONFIG, &prev, 1); /* read config */
708 if (res != 0) /* check result */
709 {
710 handle->debug_print("ens160: get config failed.\n"); /* get config failed */
711
712 return 1; /* return error */
713 }
714 prev &= ~(1 << 0); /* clear settings */
715 prev |= enable << 0; /* set bool */
716 res = a_ens160_iic_spi_write(handle, ENS160_REG_CONFIG, &prev, 1); /* write config */
717 if (res != 0) /* check result */
718 {
719 handle->debug_print("ens160: set config failed.\n"); /* set config failed */
720
721 return 1; /* return error */
722 }
723 handle->delay_ms(10); /* delay 10ms */
724
725 return 0; /* success return 0 */
726}
727
740{
741 uint8_t res;
742 uint8_t prev;
743
744 if (handle == NULL) /* check handle */
745 {
746 return 2; /* return error */
747 }
748 if (handle->inited != 1) /* check handle initialization */
749 {
750 return 3; /* return error */
751 }
752
753 res = a_ens160_iic_spi_read(handle, ENS160_REG_CONFIG, &prev, 1); /* read config */
754 if (res != 0) /* check result */
755 {
756 handle->debug_print("ens160: get config failed.\n"); /* get config failed */
757
758 return 1; /* return error */
759 }
760 *enable = (ens160_bool_t)((prev >> 0) & 0x01); /* set bool */
761
762 return 0; /* success return 0 */
763}
764
776{
777 uint8_t res;
778 uint8_t prev;
779
780 if (handle == NULL) /* check handle */
781 {
782 return 2; /* return error */
783 }
784 if (handle->inited != 1) /* check handle initialization */
785 {
786 return 3; /* return error */
787 }
788
789 prev = 0x00; /* set nop command */
790 res = a_ens160_iic_spi_write(handle, ENS160_REG_COMMAND, &prev, 1); /* write config */
791 if (res != 0) /* check result */
792 {
793 handle->debug_print("ens160: set command failed.\n"); /* set command failed */
794
795 return 1; /* return error */
796 }
797 handle->delay_ms(10); /* delay 10ms */
798
799 return 0; /* success return 0 */
800}
801
815uint8_t ens160_get_app_version(ens160_handle_t *handle, uint8_t *major, uint8_t *minor, uint8_t *release)
816{
817 uint8_t res;
818 uint8_t prev;
819 uint8_t buf[3];
820
821 if (handle == NULL) /* check handle */
822 {
823 return 2; /* return error */
824 }
825 if (handle->inited != 1) /* check handle initialization */
826 {
827 return 3; /* return error */
828 }
829
830 prev = 0x00; /* set nop command */
831 res = a_ens160_iic_spi_write(handle, ENS160_REG_COMMAND, &prev, 1); /* write config */
832 if (res != 0) /* check result */
833 {
834 handle->debug_print("ens160: set command failed.\n"); /* set command failed */
835
836 return 1; /* return error */
837 }
838 handle->delay_ms(10); /* delay 10ms */
839 prev = 0x0E; /* set get app version command */
840 res = a_ens160_iic_spi_write(handle, ENS160_REG_COMMAND, &prev, 1); /* write config */
841 if (res != 0) /* check result */
842 {
843 handle->debug_print("ens160: set command failed.\n"); /* set command failed */
844
845 return 1; /* return error */
846 }
847 handle->delay_ms(10); /* delay 10ms */
848 res = a_ens160_iic_spi_read(handle, ENS160_REG_GPR_READ + 4, buf, 3); /* read data */
849 if (res != 0) /* check result */
850 {
851 handle->debug_print("ens160: read data failed.\n"); /* read data failed */
852
853 return 1; /* return error */
854 }
855 *major = buf[0]; /* set major */
856 *minor = buf[1]; /* set minor */
857 *release = buf[2]; /* set release */
858
859 return 0; /* success return 0 */
860}
861
873{
874 uint8_t res;
875 uint8_t prev;
876
877 if (handle == NULL) /* check handle */
878 {
879 return 2; /* return error */
880 }
881 if (handle->inited != 1) /* check handle initialization */
882 {
883 return 3; /* return error */
884 }
885
886 prev = 0x00; /* set nop command */
887 res = a_ens160_iic_spi_write(handle, ENS160_REG_COMMAND, &prev, 1); /* write config */
888 if (res != 0) /* check result */
889 {
890 handle->debug_print("ens160: set command failed.\n"); /* set command failed */
891
892 return 1; /* return error */
893 }
894 handle->delay_ms(10); /* delay 10ms */
895 prev = 0xCC; /* set clear command */
896 res = a_ens160_iic_spi_write(handle, ENS160_REG_COMMAND, &prev, 1); /* write config */
897 if (res != 0) /* check result */
898 {
899 handle->debug_print("ens160: set command failed.\n"); /* set command failed */
900
901 return 1; /* return error */
902 }
903 handle->delay_ms(10); /* delay 10ms */
904
905 return 0; /* success return 0 */
906}
907
920{
921 uint8_t res;
922 uint8_t buf[2];
923
924 if (handle == NULL) /* check handle */
925 {
926 return 2; /* return error */
927 }
928 if (handle->inited != 1) /* check handle initialization */
929 {
930 return 3; /* return error */
931 }
932
933 buf[0] = (raw >> 0) & 0xFF; /* set lsb */
934 buf[1] = (raw >> 8) & 0xFF; /* set msb */
935 res = a_ens160_iic_spi_write(handle, ENS160_REG_TEMP_IN, buf, 2); /* write config */
936 if (res != 0) /* check result */
937 {
938 handle->debug_print("ens160: set temp in failed.\n"); /* set temp in failed */
939
940 return 1; /* return error */
941 }
942 handle->delay_ms(10); /* delay 10ms */
943
944 return 0; /* success return 0 */
945}
946
959{
960 uint8_t res;
961 uint8_t buf[2];
962
963 if (handle == NULL) /* check handle */
964 {
965 return 2; /* return error */
966 }
967 if (handle->inited != 1) /* check handle initialization */
968 {
969 return 3; /* return error */
970 }
971
972 res = a_ens160_iic_spi_read(handle, ENS160_REG_TEMP_IN, buf, 2); /* read config */
973 if (res != 0) /* check result */
974 {
975 handle->debug_print("ens160: get temp in failed.\n"); /* get temp in failed */
976
977 return 1; /* return error */
978 }
979 *raw = (uint16_t)((uint16_t)buf[1] << 8) | buf[0]; /* set raw */
980
981 return 0; /* success return 0 */
982}
983
996{
997 uint8_t res;
998 uint8_t buf[2];
999
1000 if (handle == NULL) /* check handle */
1001 {
1002 return 2; /* return error */
1003 }
1004 if (handle->inited != 1) /* check handle initialization */
1005 {
1006 return 3; /* return error */
1007 }
1008
1009 buf[0] = (raw >> 0) & 0xFF; /* set lsb */
1010 buf[1] = (raw >> 8) & 0xFF; /* set msb */
1011 res = a_ens160_iic_spi_write(handle, ENS160_REG_RH_IN, buf, 2); /* write config */
1012 if (res != 0) /* check result */
1013 {
1014 handle->debug_print("ens160: set rh in failed.\n"); /* set rh in failed */
1015
1016 return 1; /* return error */
1017 }
1018 handle->delay_ms(10); /* delay 10ms */
1019
1020 return 0; /* success return 0 */
1021}
1022
1035{
1036 uint8_t res;
1037 uint8_t buf[2];
1038
1039 if (handle == NULL) /* check handle */
1040 {
1041 return 2; /* return error */
1042 }
1043 if (handle->inited != 1) /* check handle initialization */
1044 {
1045 return 3; /* return error */
1046 }
1047
1048 res = a_ens160_iic_spi_read(handle, ENS160_REG_RH_IN, buf, 2); /* read config */
1049 if (res != 0) /* check result */
1050 {
1051 handle->debug_print("ens160: get rh in failed.\n"); /* get rh in failed */
1052
1053 return 1; /* return error */
1054 }
1055 *raw = (uint16_t)((uint16_t)buf[1] << 8) | buf[0]; /* set raw */
1056
1057 return 0; /* success return 0 */
1058}
1059
1071uint8_t ens160_get_status(ens160_handle_t *handle, uint8_t *status)
1072{
1073 uint8_t res;
1074 uint8_t prev;
1075
1076 if (handle == NULL) /* check handle */
1077 {
1078 return 2; /* return error */
1079 }
1080 if (handle->inited != 1) /* check handle initialization */
1081 {
1082 return 3; /* return error */
1083 }
1084
1085 res = a_ens160_iic_spi_read(handle, ENS160_REG_DEVICE_STATUS, &prev, 1); /* read status */
1086 if (res != 0) /* check result */
1087 {
1088 handle->debug_print("ens160: get status failed.\n"); /* get status failed */
1089
1090 return 1; /* return error */
1091 }
1092 *status = prev; /* set status */
1093
1094 return 0; /* success return 0 */
1095}
1096
1108uint8_t ens160_read_aqi(ens160_handle_t *handle, uint8_t *uba)
1109{
1110 uint8_t res;
1111 uint8_t prev;
1112
1113 if (handle == NULL) /* check handle */
1114 {
1115 return 2; /* return error */
1116 }
1117 if (handle->inited != 1) /* check handle initialization */
1118 {
1119 return 3; /* return error */
1120 }
1121
1122 res = a_ens160_iic_spi_read(handle, ENS160_REG_DATA_AQI, &prev, 1); /* read aqi */
1123 if (res != 0) /* check result */
1124 {
1125 handle->debug_print("ens160: read aqi failed.\n"); /* read aqi failed */
1126
1127 return 1; /* return error */
1128 }
1129 *uba = prev & 0x7; /* set uba */
1130
1131 return 0; /* success return 0 */
1132}
1133
1145uint8_t ens160_read_tvoc(ens160_handle_t *handle, uint16_t *tvoc_ppb)
1146{
1147 uint8_t res;
1148 uint8_t buf[2];
1149
1150 if (handle == NULL) /* check handle */
1151 {
1152 return 2; /* return error */
1153 }
1154 if (handle->inited != 1) /* check handle initialization */
1155 {
1156 return 3; /* return error */
1157 }
1158
1159 res = a_ens160_iic_spi_read(handle, ENS160_REG_DATA_TVOC, buf, 2); /* read tvoc */
1160 if (res != 0) /* check result */
1161 {
1162 handle->debug_print("ens160: read tvoc failed.\n"); /* read tvoc failed */
1163
1164 return 1; /* return error */
1165 }
1166 *tvoc_ppb = (uint16_t)((uint16_t)buf[1] << 8) | buf[0]; /* set tvoc ppb */
1167
1168 return 0; /* success return 0 */
1169}
1170
1182uint8_t ens160_read_eco2(ens160_handle_t *handle, uint16_t *eco2_ppm)
1183{
1184 uint8_t res;
1185 uint8_t buf[2];
1186
1187 if (handle == NULL) /* check handle */
1188 {
1189 return 2; /* return error */
1190 }
1191 if (handle->inited != 1) /* check handle initialization */
1192 {
1193 return 3; /* return error */
1194 }
1195
1196 res = a_ens160_iic_spi_read(handle, ENS160_REG_DATA_ECO2, buf, 2); /* read eco2 */
1197 if (res != 0) /* check result */
1198 {
1199 handle->debug_print("ens160: read eco2 failed.\n"); /* read eco2 failed */
1200
1201 return 1; /* return error */
1202 }
1203 *eco2_ppm = (uint16_t)((uint16_t)buf[1] << 8) | buf[0]; /* set eco2 ppm */
1204
1205 return 0; /* success return 0 */
1206}
1207
1219uint8_t ens160_read_etoh(ens160_handle_t *handle, uint16_t *etoh_ppb)
1220{
1221 uint8_t res;
1222 uint8_t buf[2];
1223
1224 if (handle == NULL) /* check handle */
1225 {
1226 return 2; /* return error */
1227 }
1228 if (handle->inited != 1) /* check handle initialization */
1229 {
1230 return 3; /* return error */
1231 }
1232
1233 res = a_ens160_iic_spi_read(handle, ENS160_REG_DATA_ETOH, buf, 2); /* read etoh */
1234 if (res != 0) /* check result */
1235 {
1236 handle->debug_print("ens160: read etoh failed.\n"); /* read etoh failed */
1237
1238 return 1; /* return error */
1239 }
1240 *etoh_ppb = (uint16_t)((uint16_t)buf[1] << 8) | buf[0]; /* set etoh ppb */
1241
1242 return 0; /* success return 0 */
1243}
1244
1257{
1258 uint8_t res;
1259 uint8_t buf[2];
1260
1261 if (handle == NULL) /* check handle */
1262 {
1263 return 2; /* return error */
1264 }
1265 if (handle->inited != 1) /* check handle initialization */
1266 {
1267 return 3; /* return error */
1268 }
1269
1270 res = a_ens160_iic_spi_read(handle, ENS160_REG_DATA_T, buf, 2); /* read data */
1271 if (res != 0) /* check result */
1272 {
1273 handle->debug_print("ens160: get data failed.\n"); /* get data failed */
1274
1275 return 1; /* return error */
1276 }
1277 *raw = (uint16_t)((uint16_t)buf[1] << 8) | buf[0]; /* set raw */
1278
1279 return 0; /* success return 0 */
1280}
1281
1294{
1295 uint8_t res;
1296 uint8_t buf[2];
1297
1298 if (handle == NULL) /* check handle */
1299 {
1300 return 2; /* return error */
1301 }
1302 if (handle->inited != 1) /* check handle initialization */
1303 {
1304 return 3; /* return error */
1305 }
1306
1307 res = a_ens160_iic_spi_read(handle, ENS160_REG_DATA_RH, buf, 2); /* read data */
1308 if (res != 0) /* check result */
1309 {
1310 handle->debug_print("ens160: get data failed.\n"); /* get data failed */
1311
1312 return 1; /* return error */
1313 }
1314 *raw = (uint16_t)((uint16_t)buf[1] << 8) | buf[0]; /* set raw */
1315
1316 return 0; /* success return 0 */
1317}
1318
1330uint8_t ens160_get_checksum(ens160_handle_t *handle, uint8_t *checksum)
1331{
1332 uint8_t res;
1333 uint8_t prev;
1334
1335 if (handle == NULL) /* check handle */
1336 {
1337 return 2; /* return error */
1338 }
1339 if (handle->inited != 1) /* check handle initialization */
1340 {
1341 return 3; /* return error */
1342 }
1343
1344 res = a_ens160_iic_spi_read(handle, ENS160_REG_DATA_MISR, &prev, 1); /* get checksum */
1345 if (res != 0) /* check result */
1346 {
1347 handle->debug_print("ens160: get checksum failed.\n"); /* get checksum failed */
1348
1349 return 1; /* return error */
1350 }
1351 *checksum = prev; /* set checksum */
1352
1353 return 0; /* success return 0 */
1354}
1355
1367uint8_t ens160_set_params(ens160_handle_t *handle, uint8_t params[8])
1368{
1369 uint8_t res;
1370
1371 if (handle == NULL) /* check handle */
1372 {
1373 return 2; /* return error */
1374 }
1375 if (handle->inited != 1) /* check handle initialization */
1376 {
1377 return 3; /* return error */
1378 }
1379
1380 res = a_ens160_iic_spi_write(handle, ENS160_REG_GPR_WRITE, params, 8); /* set params */
1381 if (res != 0) /* check result */
1382 {
1383 handle->debug_print("ens160: set params failed.\n"); /* set params failed */
1384
1385 return 1; /* return error */
1386 }
1387
1388 return 0; /* success return 0 */
1389}
1390
1402uint8_t ens160_get_params(ens160_handle_t *handle, uint8_t params[8])
1403{
1404 uint8_t res;
1405
1406 if (handle == NULL) /* check handle */
1407 {
1408 return 2; /* return error */
1409 }
1410 if (handle->inited != 1) /* check handle initialization */
1411 {
1412 return 3; /* return error */
1413 }
1414
1415 res = a_ens160_iic_spi_read(handle, ENS160_REG_GPR_WRITE, params, 8); /* get params */
1416 if (res != 0) /* check result */
1417 {
1418 handle->debug_print("ens160: get params failed.\n"); /* get params failed */
1419
1420 return 1; /* return error */
1421 }
1422
1423 return 0; /* success return 0 */
1424}
1425
1437uint8_t ens160_get_params_output(ens160_handle_t *handle, uint8_t params[8])
1438{
1439 uint8_t res;
1440
1441 if (handle == NULL) /* check handle */
1442 {
1443 return 2; /* return error */
1444 }
1445 if (handle->inited != 1) /* check handle initialization */
1446 {
1447 return 3; /* return error */
1448 }
1449
1450 res = a_ens160_iic_spi_read(handle, ENS160_REG_GPR_READ, params, 8); /* get params */
1451 if (res != 0) /* check result */
1452 {
1453 handle->debug_print("ens160: get params output failed.\n"); /* get params output failed */
1454
1455 return 1; /* return error */
1456 }
1457
1458 return 0; /* success return 0 */
1459}
1460
1472uint8_t ens160_temperature_convert_to_register(ens160_handle_t *handle, float celsius_deg, uint16_t *reg)
1473{
1474 if (handle == NULL) /* check handle */
1475 {
1476 return 2; /* return error */
1477 }
1478 if (handle->inited != 1) /* check handle initialization */
1479 {
1480 return 3; /* return error */
1481 }
1482
1483 *reg = (uint16_t)((celsius_deg + 273.15f) * 64.0f); /* convert real data to register data */
1484
1485 return 0; /* success return 0 */
1486}
1487
1499uint8_t ens160_temperature_convert_to_data(ens160_handle_t *handle, uint16_t reg, float *celsius_deg)
1500{
1501 if (handle == NULL) /* check handle */
1502 {
1503 return 2; /* return error */
1504 }
1505 if (handle->inited != 1) /* check handle initialization */
1506 {
1507 return 3; /* return error */
1508 }
1509
1510 *celsius_deg = (uint16_t)(((float)(reg) / 64.0f) - 273.15f); /* convert raw data to real data */
1511
1512 return 0; /* success return 0 */
1513}
1514
1526uint8_t ens160_humidity_convert_to_register(ens160_handle_t *handle, float percentage, uint16_t *reg)
1527{
1528 if (handle == NULL) /* check handle */
1529 {
1530 return 2; /* return error */
1531 }
1532 if (handle->inited != 1) /* check handle initialization */
1533 {
1534 return 3; /* return error */
1535 }
1536
1537 *reg = (uint16_t)(percentage * 512.0f); /* convert real data to register data */
1538
1539 return 0; /* success return 0 */
1540}
1541
1553uint8_t ens160_humidity_convert_to_data(ens160_handle_t *handle, uint16_t reg, float *percentage)
1554{
1555 if (handle == NULL) /* check handle */
1556 {
1557 return 2; /* return error */
1558 }
1559 if (handle->inited != 1) /* check handle initialization */
1560 {
1561 return 3; /* return error */
1562 }
1563
1564 *percentage = ((float)(reg) / 512.0f); /* convert raw data to real data */
1565
1566 return 0; /* success return 0 */
1567}
1568
1580uint8_t ens160_resistance_convert_to_register(ens160_handle_t *handle, float ohm, uint16_t *reg)
1581{
1582 if (handle == NULL) /* check handle */
1583 {
1584 return 2; /* return error */
1585 }
1586 if (handle->inited != 1) /* check handle initialization */
1587 {
1588 return 3; /* return error */
1589 }
1590
1591 *reg = (uint16_t)(log2f(ohm) * 2048.0f); /* convert real data to register data */
1592
1593 return 0; /* success return 0 */
1594}
1595
1607uint8_t ens160_resistance_convert_to_data(ens160_handle_t *handle, uint16_t reg, float *ohm)
1608{
1609 if (handle == NULL) /* check handle */
1610 {
1611 return 2; /* return error */
1612 }
1613 if (handle->inited != 1) /* check handle initialization */
1614 {
1615 return 3; /* return error */
1616 }
1617
1618 *ohm = powf(2.0f, (float)reg / 2048.0f); /* convert raw data to real data */
1619
1620 return 0; /* success return 0 */
1621}
1622
1637uint8_t ens160_resistance_split(ens160_handle_t *handle, uint8_t raw[8],
1638 uint16_t *resistance0, uint16_t *resistance1,
1639 uint16_t *resistance2, uint16_t *resistance3)
1640{
1641 if (handle == NULL) /* check handle */
1642 {
1643 return 2; /* return error */
1644 }
1645 if (handle->inited != 1) /* check handle initialization */
1646 {
1647 return 3; /* return error */
1648 }
1649
1650 *resistance0 = (uint16_t)((uint16_t)raw[1] << 8) | raw[0]; /* set resistance0 */
1651 *resistance1 = (uint16_t)((uint16_t)raw[3] << 8) | raw[2]; /* set resistance1 */
1652 *resistance2 = (uint16_t)((uint16_t)raw[5] << 8) | raw[4]; /* set resistance2 */
1653 *resistance3 = (uint16_t)((uint16_t)raw[7] << 8) | raw[6]; /* set resistance3 */
1654
1655 return 0; /* success return 0 */
1656}
1657
1678{
1679 uint8_t res;
1680 uint8_t prev;
1681
1682 if (handle == NULL) /* check handle */
1683 {
1684 return 2; /* return error */
1685 }
1686 if (handle->inited != 1) /* check handle initialization */
1687 {
1688 return 3; /* return error */
1689 }
1690
1691 res = a_ens160_iic_spi_read(handle, ENS160_REG_DEVICE_STATUS, &prev, 1); /* read status */
1692 if (res != 0) /* check result */
1693 {
1694 handle->debug_print("ens160: get status failed.\n"); /* get status failed */
1695
1696 return 1; /* return error */
1697 }
1698
1699 if ((prev & (uint8_t)ENS160_STATUS_NEWDAT) != 0) /* check new data */
1700 {
1701 uint8_t prev2;
1702 uint8_t buf[2];
1703 uint16_t raw[4];
1704
1705 res = a_ens160_iic_spi_read(handle, ENS160_REG_DATA_AQI, &prev2, 1); /* read aqi */
1706 if (res != 0) /* check result */
1707 {
1708 handle->debug_print("ens160: read aqi failed.\n"); /* read aqi failed */
1709
1710 return 1; /* return error */
1711 }
1712 raw[0] = prev2 & 0x7; /* set raw */
1713
1714 res = a_ens160_iic_spi_read(handle, ENS160_REG_DATA_TVOC, buf, 2); /* read tvoc */
1715 if (res != 0) /* check result */
1716 {
1717 handle->debug_print("ens160: read tvoc failed.\n"); /* read tvoc failed */
1718
1719 return 1; /* return error */
1720 }
1721 raw[1] = (uint16_t)((uint16_t)buf[1] << 8) | buf[0]; /* set tvoc ppb */
1722 raw[3] = (uint16_t)((uint16_t)buf[1] << 8) | buf[0]; /* set etoh ppb */
1723
1724 res = a_ens160_iic_spi_read(handle, ENS160_REG_DATA_ECO2, buf, 2); /* read eco2 */
1725 if (res != 0) /* check result */
1726 {
1727 handle->debug_print("ens160: read eco2 failed.\n"); /* read eco2 failed */
1728
1729 return 1; /* return error */
1730 }
1731 raw[2] = (uint16_t)((uint16_t)buf[1] << 8) | buf[0]; /* set eco2 ppm */
1732
1733 if (handle->receive_callback != NULL) /* not null */
1734 {
1735 handle->receive_callback((uint8_t)ENS160_STATUS_NEWDAT, raw); /* run the callback */
1736 }
1737 }
1738 if ((prev & (uint8_t)ENS160_STATUS_NEWGPR) != 0) /* check new gpr */
1739 {
1740 uint8_t params[8];
1741 uint16_t raw[4];
1742
1743 res = a_ens160_iic_spi_read(handle, ENS160_REG_GPR_READ, params, 8); /* get params */
1744 if (res != 0) /* check result */
1745 {
1746 handle->debug_print("ens160: get params output failed.\n"); /* get params output failed */
1747
1748 return 1; /* return error */
1749 }
1750 raw[0] = (uint16_t)((uint16_t)params[1] << 8) | params[0]; /* set resistance0 */
1751 raw[1] = (uint16_t)((uint16_t)params[3] << 8) | params[2]; /* set resistance1 */
1752 raw[2] = (uint16_t)((uint16_t)params[5] << 8) | params[4]; /* set resistance2 */
1753 raw[3] = (uint16_t)((uint16_t)params[7] << 8) | params[6]; /* set resistance3 */
1754
1755 if (handle->receive_callback != NULL) /* not null */
1756 {
1757 handle->receive_callback((uint8_t)ENS160_STATUS_NEWGPR, raw); /* run the callback */
1758 }
1759 }
1760
1761 return 0; /* success return 0 */
1762}
1763
1772static uint8_t a_ens160_close(ens160_handle_t *handle)
1773{
1774 if (handle->iic_spi == ENS160_INTERFACE_IIC) /* iic interface */
1775 {
1776 if (handle->iic_deinit() != 0) /* iic deinit */
1777 {
1778 handle->debug_print("ens160: iic deinit failed.\n"); /* iic deinit failed */
1779
1780 return 1; /* return error */
1781 }
1782
1783 return 0; /* success return 0 */
1784 }
1785 else /* spi interface */
1786 {
1787 if (handle->spi_deinit() != 0) /* spi deinit */
1788 {
1789 handle->debug_print("ens160: spi deinit failed.\n"); /* spi deinit failed */
1790
1791 return 1; /* return error */
1792 }
1793
1794 return 0; /* success return 0 */
1795 }
1796}
1797
1810{
1811 uint8_t buf[2];
1812 uint16_t id;
1813
1814 if (handle == NULL) /* check handle */
1815 {
1816 return 2; /* return error */
1817 }
1818 if (handle->debug_print == NULL) /* check debug_print */
1819 {
1820 return 3; /* return error */
1821 }
1822 if (handle->iic_init == NULL) /* check iic_init */
1823 {
1824 handle->debug_print("ens160: iic_init is null.\n"); /* iic_init is null */
1825
1826 return 3; /* return error */
1827 }
1828 if (handle->iic_deinit == NULL) /* check iic_deinit */
1829 {
1830 handle->debug_print("ens160: iic_deinit is null.\n"); /* iic_deinit is null */
1831
1832 return 3; /* return error */
1833 }
1834 if (handle->iic_read == NULL) /* check iic_read */
1835 {
1836 handle->debug_print("ens160: iic_read is null.\n"); /* iic_read is null */
1837
1838 return 3; /* return error */
1839 }
1840 if (handle->iic_write == NULL) /* check iic_write */
1841 {
1842 handle->debug_print("ens160: iic_write is null.\n"); /* iic_write is null */
1843
1844 return 3; /* return error */
1845 }
1846 if (handle->spi_init == NULL) /* check spi_init */
1847 {
1848 handle->debug_print("ens160: spi_init is null.\n"); /* spi_init is null */
1849
1850 return 3; /* return error */
1851 }
1852 if (handle->spi_deinit == NULL) /* check spi_deinit */
1853 {
1854 handle->debug_print("ens160: spi_deinit is null.\n"); /* spi_deinit is null */
1855
1856 return 3; /* return error */
1857 }
1858 if (handle->spi_read == NULL) /* check spi_read */
1859 {
1860 handle->debug_print("ens160: spi_read is null.\n"); /* spi_read is null */
1861
1862 return 3; /* return error */
1863 }
1864 if (handle->spi_write == NULL) /* check spi_write */
1865 {
1866 handle->debug_print("ens160: spi_write is null.\n"); /* spi_write is null */
1867
1868 return 3; /* return error */
1869 }
1870 if (handle->delay_ms == NULL) /* check delay_ms */
1871 {
1872 handle->debug_print("ens160: delay_ms is null.\n"); /* delay_ms is null */
1873
1874 return 3; /* return error */
1875 }
1876 if (handle->receive_callback == NULL) /* check receive_callback */
1877 {
1878 handle->debug_print("ens160: receive_callback is null.\n"); /* receive_callback is null */
1879
1880 return 3; /* return error */
1881 }
1882
1883 if (handle->iic_spi == ENS160_INTERFACE_IIC) /* iic interface */
1884 {
1885 if (handle->iic_init() != 0) /* initialize iic bus */
1886 {
1887 handle->debug_print("ens160: iic init failed.\n"); /* iic init failed */
1888
1889 return 1; /* return error */
1890 }
1891 }
1892 else /* spi interface */
1893 {
1894 if (handle->spi_init() != 0) /* initialize spi bus */
1895 {
1896 handle->debug_print("ens160: spi init failed.\n"); /* spi init failed */
1897
1898 return 1; /* return error */
1899 }
1900 }
1901
1902 if (a_ens160_iic_spi_read(handle, ENS160_REG_PART_ID , buf, 2) != 0) /* read id */
1903 {
1904 handle->debug_print("ens160: read failed.\n"); /* read failed */
1905 (void)a_ens160_close(handle); /* close */
1906
1907 return 4; /* return error */
1908 }
1909 id = (uint16_t)((uint16_t)buf[1] << 8) | buf[0]; /* set id */
1910 if (id != 0x0160) /* check id */
1911 {
1912 handle->debug_print("ens160: id is invalid.\n"); /* id is invalid */
1913 (void)a_ens160_close(handle); /* close */
1914
1915 return 4; /* return error */
1916 }
1917 handle->inited = 1; /* flag finish initialization */
1918
1919 return 0; /* success return 0 */
1920}
1921
1934{
1935 uint8_t res;
1936 uint8_t prev;
1937
1938 if (handle == NULL) /* check handle */
1939 {
1940 return 2; /* return error */
1941 }
1942 if (handle->inited != 1) /* check handle initialization */
1943 {
1944 return 3; /* return error */
1945 }
1946
1947 prev = 0x00; /* set mode */
1948 res = a_ens160_iic_spi_write(handle, ENS160_REG_OPMODE, &prev, 1); /* write config */
1949 if (res != 0) /* check result */
1950 {
1951 handle->debug_print("ens160: set mode failed.\n"); /* set mode failed */
1952
1953 return 4; /* return error */
1954 }
1955 res = a_ens160_close(handle); /* close */
1956 if (res != 0) /* check result */
1957 {
1958 return 1; /* return error */
1959 }
1960 handle->inited = 0; /* flag close */
1961
1962 return 0; /* success return 0 */
1963}
1964
1978uint8_t ens160_set_reg(ens160_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
1979{
1980 if (handle == NULL) /* check handle */
1981 {
1982 return 2; /* return error */
1983 }
1984 if (handle->inited != 1) /* check handle initialization */
1985 {
1986 return 3; /* return error */
1987 }
1988
1989 return a_ens160_iic_spi_write(handle, reg, buf, len); /* write data */
1990}
1991
2005uint8_t ens160_get_reg(ens160_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
2006{
2007 if (handle == NULL) /* check handle */
2008 {
2009 return 2; /* return error */
2010 }
2011 if (handle->inited != 1) /* check handle initialization */
2012 {
2013 return 3; /* return error */
2014 }
2015
2016 return a_ens160_iic_spi_read(handle, reg, buf, len); /* read data */
2017}
2018
2028{
2029 if (info == NULL) /* check handle */
2030 {
2031 return 2; /* return error */
2032 }
2033
2034 memset(info, 0, sizeof(ens160_info_t)); /* initialize ens160 info structure */
2035 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
2036 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
2037 strncpy(info->interface, "IIC SPI", 8); /* copy interface name */
2038 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
2039 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
2040 info->max_current_ma = MAX_CURRENT; /* set maximum current */
2041 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
2042 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
2043 info->driver_version = DRIVER_VERSION; /* set driver version */
2044
2045 return 0; /* success return 0 */
2046}
#define ENS160_REG_OPMODE
#define ENS160_REG_COMMAND
#define MAX_CURRENT
#define ENS160_REG_DATA_T
#define ENS160_REG_DATA_MISR
#define ENS160_REG_GPR_WRITE
#define ENS160_REG_GPR_READ
#define SUPPLY_VOLTAGE_MAX
#define ENS160_REG_CONFIG
#define ENS160_REG_DATA_ETOH
#define TEMPERATURE_MAX
#define ENS160_REG_DATA_AQI
#define MANUFACTURER_NAME
#define ENS160_REG_TEMP_IN
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define ENS160_REG_RH_IN
#define ENS160_REG_PART_ID
chip register definition
#define ENS160_REG_DATA_ECO2
#define ENS160_REG_DATA_TVOC
#define CHIP_NAME
chip register definition
#define DRIVER_VERSION
#define ENS160_REG_DEVICE_STATUS
#define ENS160_REG_DATA_RH
driver ens160 header file
ens160_mode_t
ens160 mode enumeration definition
uint8_t ens160_resistance_convert_to_register(ens160_handle_t *handle, float ohm, uint16_t *reg)
convert the resistance to the register raw data
ens160_address_t
ens160 address enumeration definition
uint8_t ens160_get_status(ens160_handle_t *handle, uint8_t *status)
get status
uint8_t ens160_resistance_convert_to_data(ens160_handle_t *handle, uint16_t reg, float *ohm)
convert the register raw data to the resistance
uint8_t ens160_set_params(ens160_handle_t *handle, uint8_t params[8])
set params
uint8_t ens160_deinit(ens160_handle_t *handle)
close the chip
uint8_t ens160_set_addr_pin(ens160_handle_t *handle, ens160_address_t addr_pin)
set the iic address pin
uint8_t ens160_set_interrupt_pin_drive(ens160_handle_t *handle, ens160_pin_drive_t drive)
set interrupt pin drive
ens160_pin_polarity_t
ens160 pin polarity enumeration definition
uint8_t ens160_read_eco2(ens160_handle_t *handle, uint16_t *eco2_ppm)
read eco2
struct ens160_info_s ens160_info_t
ens160 information structure definition
uint8_t ens160_get_data_interrupt_pin_asserted(ens160_handle_t *handle, ens160_bool_t *enable)
get data interrupt pin asserted
uint8_t ens160_humidity_convert_to_data(ens160_handle_t *handle, uint16_t reg, float *percentage)
convert the register raw data to the humidity
uint8_t ens160_info(ens160_info_t *info)
get chip's information
uint8_t ens160_clear(ens160_handle_t *handle)
clear
uint8_t ens160_get_temperature_compensation(ens160_handle_t *handle, uint16_t *raw)
get temperature compensation
uint8_t ens160_temperature_convert_to_register(ens160_handle_t *handle, float celsius_deg, uint16_t *reg)
convert the temperature to the register raw data
uint8_t ens160_get_params_output(ens160_handle_t *handle, uint8_t params[8])
get params output
uint8_t ens160_get_params(ens160_handle_t *handle, uint8_t params[8])
get params
uint8_t ens160_get_interrupt_pin_polarity(ens160_handle_t *handle, ens160_pin_polarity_t *polarity)
get interrupt pin polarity
uint8_t ens160_set_interface(ens160_handle_t *handle, ens160_interface_t interface)
set the chip interface
uint8_t ens160_soft_reset(ens160_handle_t *handle)
soft reset
uint8_t ens160_read_tvoc(ens160_handle_t *handle, uint16_t *tvoc_ppb)
read tvoc
uint8_t ens160_set_interrupt_pin_polarity(ens160_handle_t *handle, ens160_pin_polarity_t polarity)
set interrupt pin polarity
uint8_t ens160_set_mode(ens160_handle_t *handle, ens160_mode_t mode)
set mode
uint8_t ens160_humidity_convert_to_register(ens160_handle_t *handle, float percentage, uint16_t *reg)
convert the humidity to the register raw data
uint8_t ens160_get_interrupt_pin_drive(ens160_handle_t *handle, ens160_pin_drive_t *drive)
get interrupt pin drive
uint8_t ens160_set_humidity_compensation(ens160_handle_t *handle, uint16_t raw)
set humidity compensation
ens160_interface_t
ens160 interface enumeration definition
uint8_t ens160_set_interrupt(ens160_handle_t *handle, ens160_bool_t enable)
enable or disable interrupt
uint8_t ens160_get_mode(ens160_handle_t *handle, ens160_mode_t *mode)
get mode
uint8_t ens160_set_general_purpose_read_interrupt_pin_asserted(ens160_handle_t *handle, ens160_bool_t enable)
set general purpose read interrupt pin asserted
uint8_t ens160_read_aqi(ens160_handle_t *handle, uint8_t *uba)
read aqi
uint8_t ens160_irq_handler(ens160_handle_t *handle)
irq handler
uint8_t ens160_temperature_convert_to_data(ens160_handle_t *handle, uint16_t reg, float *celsius_deg)
convert the register raw data to the temperature
uint8_t ens160_get_interface(ens160_handle_t *handle, ens160_interface_t *interface)
get the chip interface
uint8_t ens160_get_humidity_compensation(ens160_handle_t *handle, uint16_t *raw)
get humidity compensation
uint8_t ens160_get_general_purpose_read_interrupt_pin_asserted(ens160_handle_t *handle, ens160_bool_t *enable)
get general purpose read interrupt pin asserted
ens160_bool_t
ens160 bool enumeration definition
uint8_t ens160_get_addr_pin(ens160_handle_t *handle, ens160_address_t *addr_pin)
get the iic address pin
uint8_t ens160_get_interrupt(ens160_handle_t *handle, ens160_bool_t *enable)
get interrupt
ens160_pin_drive_t
ens160 pin drive enumeration definition
uint8_t ens160_get_calculation_temperature(ens160_handle_t *handle, uint16_t *raw)
get calculation temperature
uint8_t ens160_get_app_version(ens160_handle_t *handle, uint8_t *major, uint8_t *minor, uint8_t *release)
get app version
struct ens160_handle_s ens160_handle_t
ens160 handle structure definition
uint8_t ens160_resistance_split(ens160_handle_t *handle, uint8_t raw[8], uint16_t *resistance0, uint16_t *resistance1, uint16_t *resistance2, uint16_t *resistance3)
resistance split
uint8_t ens160_get_calculation_humidity(ens160_handle_t *handle, uint16_t *raw)
get calculation humidity
uint8_t ens160_nop(ens160_handle_t *handle)
nop
uint8_t ens160_set_temperature_compensation(ens160_handle_t *handle, uint16_t raw)
set temperature compensation
uint8_t ens160_init(ens160_handle_t *handle)
initialize the chip
uint8_t ens160_set_data_interrupt_pin_asserted(ens160_handle_t *handle, ens160_bool_t enable)
set data interrupt pin asserted
uint8_t ens160_get_checksum(ens160_handle_t *handle, uint8_t *checksum)
get checksum
uint8_t ens160_read_etoh(ens160_handle_t *handle, uint16_t *etoh_ppb)
read etoh
@ ENS160_INTERFACE_IIC
@ ENS160_STATUS_NEWDAT
@ ENS160_STATUS_NEWGPR
uint8_t ens160_get_reg(ens160_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
uint8_t ens160_set_reg(ens160_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
uint8_t(* spi_init)(void)
void(* delay_ms)(uint32_t ms)
uint8_t(* spi_read)(uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* spi_write)(uint8_t reg, uint8_t *buf, uint16_t len)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* spi_deinit)(void)
void(* receive_callback)(uint8_t type, uint16_t *dat)
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)
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]