temphum12  2.0.0.0
temphum12.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef TEMPHUM12_H
36 #define TEMPHUM12_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_in.h"
49 #include "drv_i2c_master.h"
50 
51 // -------------------------------------------------------------- PUBLIC MACROS
61 #define TEMPHUM12_MAP_MIKROBUS( cfg, mikrobus ) \
62  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
63  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
64  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
65 
71 #define TEMPHUM12_RETVAL uint8_t
72 
73 #define TEMPHUM12_OK 0x00
74 #define TEMPHUM12_INIT_ERROR 0xFF
75 
81 #define TEMPHUM12_REG_TEMPERATURE_LSB 0x00
82 #define TEMPHUM12_REG_TEMPERATURE_MSB 0x01
83 #define TEMPHUM12_REG_HUMIDITY_LSB 0x02
84 #define TEMPHUM12_REG_HUMIDITY_MSB 0x03
85 #define TEMPHUM12_REG_DRDY_INTERRUPT 0x04
86 #define TEMPHUM12_REG_TEMP_MAX 0x05
87 #define TEMPHUM12_REG_HUM_MAX 0x06
88 #define TEMPHUM12_REG_INT_ENABLE 0x07
89 #define TEMPHUM12_REG_TEMP_OFFSET 0x08
90 #define TEMPHUM12_REG_HUM_OFFSET 0x09
91 #define TEMPHUM12_REG_TEMP_THR_LSB 0x0A
92 #define TEMPHUM12_REG_TEMP_THR_MSB 0x0B
93 #define TEMPHUM12_REG_HUM_THR_LSB 0x0C
94 #define TEMPHUM12_REG_HUM_THR_MSB 0x0D
95 #define TEMPHUM12_REG_DRDY_INT_CONFIG 0x0E
96 #define TEMPHUM12_REG_CONFIGURATION 0x0F
97 #define TEMPHUM12_REG_MANUFACTURER_ID_LSB 0xFC
98 #define TEMPHUM12_REG_MANUFACTURER_ID_MSB 0xFD
99 #define TEMPHUM12_REG_DEVICE_ID_LSB 0xFE
100 #define TEMPHUM12_REG_DEVICE_ID_MSB 0xFF
101 
107 #define TEMPHUM12_REG_DATA_TEMPERATURE 0x00
108 #define TEMPHUM12_REG_DATA_HUMIDITY 0x02
109 #define TEMPHUM12_REG_DATA_TEMP_THR 0x0A
110 #define TEMPHUM12_REG_DATA_HUM_THR 0x0C
111 #define TEMPHUM12_REG_DATA_MANUFACTURER_ID 0xFC
112 #define TEMPHUM12_REG_DATA_DEVICE_ID 0xFE
113 
119 #define TEMPHUM12_INT_STATUS_DRDY 0x80
120 #define TEMPHUM12_INT_STATUS_TEMP_THR_HIGH 0x40
121 #define TEMPHUM12_INT_STATUS_TEMP_THR_LOW 0x20
122 #define TEMPHUM12_INT_STATUS_HUM_THR_HIGH 0x10
123 #define TEMPHUM12_INT_STATUS_HUM_THR_LOW 0x08
124 
130 #define TEMPHUM12_INTE_DRDY_ENABLE 0x80
131 #define TEMPHUM12_INTE_DRDY_DISABLE 0x00
132 #define TEMPHUM12_INTE_TEMP_TH_ENABLE 0x40
133 #define TEMPHUM12_INTE_TEMP_TH_DISABLE 0x00
134 #define TEMPHUM12_INTE_TEMP_TL_ENABLE 0x20
135 #define TEMPHUM12_INTE_TEMP_TL_DISABLE 0x00
136 #define TEMPHUM12_INTE_HUM_TH_ENABLE 0x10
137 #define TEMPHUM12_INTE_HUM_TH_DISABLE 0x00
138 #define TEMPHUM12_INTE_HUM_TL_ENABLE 0x08
139 #define TEMPHUM12_INTE_HUM_TL_DISABLE 0x00
140 
146 #define TEMPHUM12_TO_PLUS_0_16C 0x01
147 #define TEMPHUM12_TO_PLUS_0_32C 0x02
148 #define TEMPHUM12_TO_PLUS_0_64C 0x04
149 #define TEMPHUM12_TO_PLUS_1_28C 0x08
150 #define TEMPHUM12_TO_PLUS_2_58C 0x10
151 #define TEMPHUM12_TO_PLUS_5_16C 0x20
152 #define TEMPHUM12_TO_PLUS_10_32C 0x40
153 #define TEMPHUM12_TO_MINUS_20_62C 0x80
154 
160 #define TEMPHUM12_RHO_PLUS_0_2RH 0x01
161 #define TEMPHUM12_RHO_PLUS_0_4RH 0x02
162 #define TEMPHUM12_RHO_PLUS_0_8RH 0x04
163 #define TEMPHUM12_RHO_PLUS_1_6RH 0x08
164 #define TEMPHUM12_RHO_PLUS_3_1RH 0x10
165 #define TEMPHUM12_RHO_PLUS_6_3RH 0x20
166 #define TEMPHUM12_RHO_PLUS_12_5RH 0x40
167 #define TEMPHUM12_RHO_MINUS_25RH 0x80
168 
174 #define TEMPHUM12_ICFG_NORAML_OPERATION 0x00
175 #define TEMPHUM12_ICFG_SOFTWARE_RESET 0x80
176 #define TEMPHUM12_ICFG_AMM_1_120Hz 0x10
177 #define TEMPHUM12_ICFG_AMM_1_60Hz 0x20
178 #define TEMPHUM12_ICFG_AMM_0p1Hz 0x30
179 #define TEMPHUM12_ICFG_AMM_0p2Hz 0x40
180 #define TEMPHUM12_ICFG_AMM_1Hz 0x50
181 #define TEMPHUM12_ICFG_AMM_2Hz 0x60
182 #define TEMPHUM12_ICFG_AMM_5Hz 0x70
183 #define TEMPHUM12_ICFG_HEATER_DISABLE 0x00
184 #define TEMPHUM12_ICFG_HEATER_ENABLE 0x08
185 #define TEMPHUM12_ICFG_DRDY_ENABLE 0x04
186 #define TEMPHUM12_ICFG_INT_ACTIVE_LOW 0x00
187 #define TEMPHUM12_ICFG_INT_ACTIVE_HIGH 0x02
188 #define TEMPHUM12_ICFG_LEVEL_SENSITIVE 0x00
189 #define TEMPHUM12_ICFG_COMPARATOR_MODE 0x01
190 
196 #define TEMPHUM12_MCFG_TEMP_RES_14bit 0x00
197 #define TEMPHUM12_MCFG_TEMP_RES_11bit 0x40
198 #define TEMPHUM12_MCFG_TEMP_RES_8bit 0x80
199 #define TEMPHUM12_MCFG_HUM_RES_14bit 0x00
200 #define TEMPHUM12_MCFG_HUM_RES_11bit 0x10
201 #define TEMPHUM12_MCFG_HUM_RES_8bit 0x20
202 #define TEMPHUM12_MCFG_TEMP_HUM_READ 0x00
203 #define TEMPHUM12_MCFG_TEMP_ONLY 0x02
204 #define TEMPHUM12_MCFG_HUM_ONLY 0x04
205 #define TEMPHUM12_MCFG_TRIG_NO_ACTION 0x00
206 #define TEMPHUM12_MCFG_TRIG_START_MEASUREMENT 0x01
207 
213 #define TEMPHUM12_MANUFACTURER_ID 0x4954
214 #define TEMPHUM12_DEVICE_ID 0x07D0
215 #define TEMPHUM12_DEVICE_SLAVE_ADDRESS 0x40
216 
222 #define TEMPHUM12_TEMP_IN_CELSIUS 0x00
223 #define TEMPHUM12_TEMP_IN_KELVIN 0x01
224 #define TEMPHUM12_TEMP_IN_FAHRENHEIT 0x02
225  // End group macro
228 // --------------------------------------------------------------- PUBLIC TYPES
237 typedef struct
238 {
239  // Input pins
240 
241  digital_in_t int_pin;
242 
243  // Modules
244 
245  i2c_master_t i2c;
246 
247  // ctx variable
248 
249  uint8_t slave_address;
250 
251 } temphum12_t;
252 
256 typedef struct
257 {
258  // Communication gpio pins
259 
260  pin_name_t scl;
261  pin_name_t sda;
262 
263  // Additional gpio pins
264 
265  pin_name_t int_pin;
266 
267  // static variable
268 
269  uint32_t i2c_speed;
270  uint8_t i2c_address;
271 
273  // End types group
275 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
276 
282 #ifdef __cplusplus
283 extern "C"{
284 #endif
285 
295 
304 
332 
343 void temphum12_generic_write ( temphum12_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
344 
355 void temphum12_generic_read ( temphum12_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
356 
365 float temphum12_get_temperature ( temphum12_t *ctx, uint8_t temp_in );
366 
375 
384 
385 #ifdef __cplusplus
386 }
387 #endif
388 #endif // _TEMPHUM12_H_
389  // End public_function group
392 
393 // ------------------------------------------------------------------------- END
temphum12_t::int_pin
digital_in_t int_pin
Definition: temphum12.h:241
temphum12_init
TEMPHUM12_RETVAL temphum12_init(temphum12_t *ctx, temphum12_cfg_t *cfg)
Initialization function.
temphum12_generic_read
void temphum12_generic_read(temphum12_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
temphum12_cfg_t::sda
pin_name_t sda
Definition: temphum12.h:261
temphum12_t::slave_address
uint8_t slave_address
Definition: temphum12.h:249
temphum12_cfg_t
Click configuration structure definition.
Definition: temphum12.h:257
temphum12_get_humidity
float temphum12_get_humidity(temphum12_t *ctx)
Relative Huminidy data.
temphum12_get_temperature
float temphum12_get_temperature(temphum12_t *ctx, uint8_t temp_in)
Temperature data.
temphum12_generic_write
void temphum12_generic_write(temphum12_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
temphum12_cfg_setup
void temphum12_cfg_setup(temphum12_cfg_t *cfg)
Config Object Initialization function.
temphum12_t
Click ctx object definition.
Definition: temphum12.h:238
TEMPHUM12_RETVAL
#define TEMPHUM12_RETVAL
Definition: temphum12.h:71
temphum12_cfg_t::int_pin
pin_name_t int_pin
Definition: temphum12.h:265
temphum12_default_cfg
void temphum12_default_cfg(temphum12_t *ctx)
Click Default Configuration function.
temphum12_t::i2c
i2c_master_t i2c
Definition: temphum12.h:245
temphum12_cfg_t::scl
pin_name_t scl
Definition: temphum12.h:260
temphum12_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum12.h:270
temphum12_get_intrrupt_state
uint8_t temphum12_get_intrrupt_state(temphum12_t *ctx)
Interrupt state.
temphum12_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum12.h:269