Nordic Thingy:52
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
drv_hts221.h
1 /*
2  Copyright (c) 2010 - 2017, Nordic Semiconductor ASA
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without modification,
6  are permitted provided that the following conditions are met:
7 
8  1. Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10 
11  2. Redistributions in binary form, except as embedded into a Nordic
12  Semiconductor ASA integrated circuit in a product or a software update for
13  such product, must reproduce the above copyright notice, this list of
14  conditions and the following disclaimer in the documentation and/or other
15  materials provided with the distribution.
16 
17  3. Neither the name of Nordic Semiconductor ASA nor the names of its
18  contributors may be used to endorse or promote products derived from this
19  software without specific prior written permission.
20 
21  4. This software, with or without modification, must only be used with a
22  Nordic Semiconductor ASA integrated circuit.
23 
24  5. Any software provided in binary form under this license must not be reverse
25  engineered, decompiled, modified and/or disassembled.
26 
27  THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
28  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29  OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
30  DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
31  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
33  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
36  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  */
38 
48 #ifndef __DRV_HTS221_H__
49 #define __DRV_HTS221_H__
50 
51 #include "nrf_drv_twi.h"
52 #include <stdint.h>
53 
55 #define WHO_AM_I_REG 0x0F
56 #define WHO_AM_I_VAL 0xBC
57 
59 #define AV_CONF_REG 0x10
60 #define AV_CONF_REG_DEFAULT 0x1B
61 
63 #define AV_CONF_REG_AVGT_Pos 3
64 #define AV_CONF_REG_AVGT_Msk (7 << AV_CONF_REG_AVGT_Pos)
65 #define AV_CONF_REG_AVGT_2 0
66 #define AV_CONF_REG_AVGT_4 1
67 #define AV_CONF_REG_AVGT_8 2
68 #define AV_CONF_REG_AVGT_16 3
69 #define AV_CONF_REG_AVGT_32 4
70 #define AV_CONF_REG_AVGT_64 5
71 #define AV_CONF_REG_AVGT_128 6
72 #define AV_CONF_REG_AVGT_256 7
73 
75 #define AV_CONF_REG_AVGH_Pos 0
76 #define AV_CONF_REG_AVGH_Msk (7 << AV_CONF_REG_AVGH_Pos)
77 #define AV_CONF_REG_AVGH_4 0
78 #define AV_CONF_REG_AVGH_8 1
79 #define AV_CONF_REG_AVGH_16 2
80 #define AV_CONF_REG_AVGH_32 3
81 #define AV_CONF_REG_AVGH_64 4
82 #define AV_CONF_REG_AVGH_128 5
83 #define AV_CONF_REG_AVGH_256 6
84 #define AV_CONF_REG_AVGH_512 7
85 
87 #define CTRL_REG1 0x20
88 #define CTRL_REG1_DEFAULT 0x00
89 
91 #define CTRL_REG1_PD_Pos 7
92 #define CTRL_REG1_PD_Msk (1 << CTRL_REG1_PD_Pos)
93 #define CTRL_REG1_PD_PowerDown 0
94 #define CTRL_REG1_PD_Active 1
95 
97 #define CTRL_REG1_BDU_Pos 2
98 #define CTRL_REG1_BDU_Msk (1 << CTRL_REG1_BDU_Pos)
99 #define CTRL_REG1_BDU_Continuous 0
100 #define CTRL_REG1_BDU_Set 1
101 
103 #define CTRL_REG1_ODR_Pos 0
104 #define CTRL_REG1_ODR_Msk (3 << CTRL_REG1_ODR_Pos)
105 #define CTRL_REG1_ODR_OneShot 0
106 #define CTRL_REG1_ODR_1Hz 1
107 #define CTRL_REG1_ODR_7Hz 2
108 #define CTRL_REG1_ODR_12_5Hz 3
109 
111 #define CTRL_REG2 0x21
112 #define CTRL_REG2_DEFAULT 0x00
113 
115 #define CTRL_REG2_BOOT_Pos 7
116 #define CTRL_REG2_BOOT_Msk (1 << CTRL_REG2_BOOT_Pos)
117 #define CTRL_REG2_BOOT_Normal 0
118 #define CTRL_REG2_BOOT_Reboot 1
119 
121 #define CTRL_REG2_HEATER_Pos 1
122 #define CTRL_REG2_HEATER_Msk (1 << CTRL_REG2_HEATER_Pos)
123 #define CTRL_REG2_HEATER_Disable 0
124 #define CTRL_REG2_HEATER_Enable 1
125 
127 #define CTRL_REG2_ONE_SHOT_Pos 0
128 #define CTRL_REG2_ONE_SHOT_Msk (1 << CTRL_REG2_ONE_SHOT_Pos)
129 #define CTRL_REG2_ONE_SHOT_WaitingForStart 0
130 #define CTRL_REG2_ONE_SHOT_Start 1
131 
133 #define CTRL_REG3 0x22
134 #define CTRL_REG3_DEFAULT 0x00
135 
137 #define CTRL_REG3_DRDY_H_L_Pos 7
138 #define CTRL_REG3_DRDY_H_L_Msk (1 << CTRL_REG3_DRDY_H_L_Pos)
139 #define CTRL_REG3_DRDY_H_L_ActiveHigh 0
140 #define CTRL_REG3_DRDY_H_L_ActiveLow 1
141 
143 #define CTRL_REG3_PP_OD_Pos 6
144 #define CTRL_REG3_PP_OD_Msk (1 << CTRL_REG3_PP_OD_Pos)
145 #define CTRL_REG3_PP_OD_PushPull 0
146 #define CTRL_REG3_PP_OD_OpenDrain 1
147 
149 #define CTRL_REG3_DRDY_Pos 2
150 #define CTRL_REG3_DRDY_Msk (1 << CTRL_REG3_DRDY_Pos)
151 #define CTRL_REG3_DRDY_Disable 0
152 #define CTRL_REG3_DRDY_Enable 1
153 
155 #define STATUS_REG 0x27
156 
158 #define STATUS_REG_H_DA_Pos 1
159 #define STATUS_REG_H_DA_Msk (1 << STATUS_REG_H_DA_Pos)
160 #define STATUS_REG_H_DA_NotAvail 0
161 #define STATUS_REG_H_DA_Avail 1
162 
164 #define STATUS_REG_T_DA_Pos 0
165 #define STATUS_REG_T_DA_Msk (1 << STATUS_REG_T_DA_Pos)
166 #define STATUS_REG_T_DA_NotAvail 0
167 #define STATUS_REG_T_DA_Avail 1
168 
170 #define HUMIDITY_OUT_L_REG 0x28
171 
173 #define HUMIDITY_OUT_H_REG 0x29
174 
176 #define TEMP_OUT_L_REG 0x2A
177 
179 #define TEMP_OUT_H_REG 0x2B
180 
181 #define CALIBRATION_REGS 0x30
182 #define CALIBRATION_REGS_NUM 16
183 
186 typedef struct
187 {
188  uint8_t av_conf;
189  uint8_t ctrl_reg1;
190  uint8_t ctrl_reg2;
191  uint8_t ctrl_reg3;
193 
196 typedef struct
197 {
198  uint8_t H0_rH_x2;
199  uint8_t H1_rH_x2;
200  uint16_t T0_degC_x8;
201  uint16_t T1_degC_x8;
202  int16_t H0_T0_OUT;
203  int16_t H1_T0_OUT;
204  int16_t T0_OUT;
205  int16_t T1_OUT;
207 
210 typedef struct
211 {
212  uint8_t twi_addr;
213  uint32_t pin_int;
214  nrf_drv_twi_t const * p_twi_instance;
215  nrf_drv_twi_config_t const * p_twi_config;
217 
219 uint32_t drv_hts221_init(void);
220 
226 uint32_t drv_hts221_open(drv_hts221_twi_cfg_t const * const p_cfg);
227 
231 uint32_t drv_hts221_close(void);
232 
236 uint32_t drv_hts221_verify(void);
237 
243 uint32_t drv_hts221_cfg_set(drv_hts221_cfg_t const * const p_cfg);
244 
250 uint32_t drv_hts221_cfg_get(drv_hts221_cfg_t * p_cfg);
251 
255 uint32_t drv_hts221_status_get(uint8_t * p_status);
256 
260 uint32_t drv_hts221_calib_get(drv_hts221_calib_t * p_calib);
261 
265 uint32_t drv_hts221_humidity_get(int16_t * p_humidity);
266 
270 uint32_t drv_hts221_temperature_get(int16_t * p_temperature);
271 
275 uint32_t drv_hts221_one_shot(void);
276 
280 uint32_t drv_hts221_reboot(void);
281 
282 #endif
283