Nordic Thingy:52 v2.2.0
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 
222 uint32_t drv_hts221_init(void);
223 
229 uint32_t drv_hts221_open(drv_hts221_twi_cfg_t const * const p_cfg);
230 
234 uint32_t drv_hts221_close(void);
235 
239 uint32_t drv_hts221_verify(void);
240 
246 uint32_t drv_hts221_cfg_set(drv_hts221_cfg_t const * const p_cfg);
247 
253 uint32_t drv_hts221_cfg_get(drv_hts221_cfg_t * p_cfg);
254 
260 uint32_t drv_hts221_status_get(uint8_t * p_status);
261 
267 uint32_t drv_hts221_calib_get(drv_hts221_calib_t * p_calib);
268 
274 uint32_t drv_hts221_humidity_get(int16_t * p_humidity);
275 
281 uint32_t drv_hts221_temperature_get(int16_t * p_temperature);
282 
286 uint32_t drv_hts221_one_shot(void);
287 
291 uint32_t drv_hts221_reboot(void);
292 
293 #endif
294 
uint32_t drv_hts221_cfg_set(drv_hts221_cfg_t const *const p_cfg)
Function for configuring the HTS221 sensor according to the specified configuration.
uint32_t drv_hts221_open(drv_hts221_twi_cfg_t const *const p_cfg)
Function for opening the HTS221 driver according to the specified configuration.
uint32_t pin_int
Interrupt pin.
Definition: drv_hts221.h:213
uint32_t drv_hts221_cfg_get(drv_hts221_cfg_t *p_cfg)
Function for reading the configuration of the HTS221 sensor.
uint8_t twi_addr
TWI address on bus.
Definition: drv_hts221.h:212
nrf_drv_twi_config_t const * p_twi_config
TWI configuraion.
Definition: drv_hts221.h:215
Configuration struct for HTS221 humidity sensor.
Definition: drv_hts221.h:186
uint32_t drv_hts221_reboot(void)
Function for rebooting the HTS221 memory content.
Calibration struct.
Definition: drv_hts221.h:196
uint32_t drv_hts221_humidity_get(int16_t *p_humidity)
Function for getting the humidity data.
uint32_t drv_hts221_close(void)
Function for closing the HTS221 driver.
uint32_t drv_hts221_init(void)
Function for initializing the HTS221 driver.
uint32_t drv_hts221_verify(void)
Function for verifying the HTS221 WHO_AM_I register.
Initialization struct for the humidity driver.
Definition: drv_hts221.h:210
nrf_drv_twi_t const * p_twi_instance
TWI instance.
Definition: drv_hts221.h:214
uint32_t drv_hts221_status_get(uint8_t *p_status)
Function for getting the status.
uint32_t drv_hts221_temperature_get(int16_t *p_temperature)
Function for getting the temperature data.
uint32_t drv_hts221_one_shot(void)
Function for starting one shot conversion.
uint32_t drv_hts221_calib_get(drv_hts221_calib_t *p_calib)
Function for getting the sensor calibration data.