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 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_in.h"
53 #include "drv_i2c_master.h"
54 
55 // -------------------------------------------------------------- PUBLIC MACROS
65 #define TEMPHUM12_MAP_MIKROBUS( cfg, mikrobus ) \
66  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
67  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
68  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
69 
75 #define TEMPHUM12_RETVAL uint8_t
76 
77 #define TEMPHUM12_OK 0x00
78 #define TEMPHUM12_INIT_ERROR 0xFF
79 
85 #define TEMPHUM12_REG_TEMPERATURE_LSB 0x00
86 #define TEMPHUM12_REG_TEMPERATURE_MSB 0x01
87 #define TEMPHUM12_REG_HUMIDITY_LSB 0x02
88 #define TEMPHUM12_REG_HUMIDITY_MSB 0x03
89 #define TEMPHUM12_REG_DRDY_INTERRUPT 0x04
90 #define TEMPHUM12_REG_TEMP_MAX 0x05
91 #define TEMPHUM12_REG_HUM_MAX 0x06
92 #define TEMPHUM12_REG_INT_ENABLE 0x07
93 #define TEMPHUM12_REG_TEMP_OFFSET 0x08
94 #define TEMPHUM12_REG_HUM_OFFSET 0x09
95 #define TEMPHUM12_REG_TEMP_THR_LSB 0x0A
96 #define TEMPHUM12_REG_TEMP_THR_MSB 0x0B
97 #define TEMPHUM12_REG_HUM_THR_LSB 0x0C
98 #define TEMPHUM12_REG_HUM_THR_MSB 0x0D
99 #define TEMPHUM12_REG_DRDY_INT_CONFIG 0x0E
100 #define TEMPHUM12_REG_CONFIGURATION 0x0F
101 #define TEMPHUM12_REG_MANUFACTURER_ID_LSB 0xFC
102 #define TEMPHUM12_REG_MANUFACTURER_ID_MSB 0xFD
103 #define TEMPHUM12_REG_DEVICE_ID_LSB 0xFE
104 #define TEMPHUM12_REG_DEVICE_ID_MSB 0xFF
105 
111 #define TEMPHUM12_REG_DATA_TEMPERATURE 0x00
112 #define TEMPHUM12_REG_DATA_HUMIDITY 0x02
113 #define TEMPHUM12_REG_DATA_TEMP_THR 0x0A
114 #define TEMPHUM12_REG_DATA_HUM_THR 0x0C
115 #define TEMPHUM12_REG_DATA_MANUFACTURER_ID 0xFC
116 #define TEMPHUM12_REG_DATA_DEVICE_ID 0xFE
117 
123 #define TEMPHUM12_INT_STATUS_DRDY 0x80
124 #define TEMPHUM12_INT_STATUS_TEMP_THR_HIGH 0x40
125 #define TEMPHUM12_INT_STATUS_TEMP_THR_LOW 0x20
126 #define TEMPHUM12_INT_STATUS_HUM_THR_HIGH 0x10
127 #define TEMPHUM12_INT_STATUS_HUM_THR_LOW 0x08
128 
134 #define TEMPHUM12_INTE_DRDY_ENABLE 0x80
135 #define TEMPHUM12_INTE_DRDY_DISABLE 0x00
136 #define TEMPHUM12_INTE_TEMP_TH_ENABLE 0x40
137 #define TEMPHUM12_INTE_TEMP_TH_DISABLE 0x00
138 #define TEMPHUM12_INTE_TEMP_TL_ENABLE 0x20
139 #define TEMPHUM12_INTE_TEMP_TL_DISABLE 0x00
140 #define TEMPHUM12_INTE_HUM_TH_ENABLE 0x10
141 #define TEMPHUM12_INTE_HUM_TH_DISABLE 0x00
142 #define TEMPHUM12_INTE_HUM_TL_ENABLE 0x08
143 #define TEMPHUM12_INTE_HUM_TL_DISABLE 0x00
144 
150 #define TEMPHUM12_TO_PLUS_0_16C 0x01
151 #define TEMPHUM12_TO_PLUS_0_32C 0x02
152 #define TEMPHUM12_TO_PLUS_0_64C 0x04
153 #define TEMPHUM12_TO_PLUS_1_28C 0x08
154 #define TEMPHUM12_TO_PLUS_2_58C 0x10
155 #define TEMPHUM12_TO_PLUS_5_16C 0x20
156 #define TEMPHUM12_TO_PLUS_10_32C 0x40
157 #define TEMPHUM12_TO_MINUS_20_62C 0x80
158 
164 #define TEMPHUM12_RHO_PLUS_0_2RH 0x01
165 #define TEMPHUM12_RHO_PLUS_0_4RH 0x02
166 #define TEMPHUM12_RHO_PLUS_0_8RH 0x04
167 #define TEMPHUM12_RHO_PLUS_1_6RH 0x08
168 #define TEMPHUM12_RHO_PLUS_3_1RH 0x10
169 #define TEMPHUM12_RHO_PLUS_6_3RH 0x20
170 #define TEMPHUM12_RHO_PLUS_12_5RH 0x40
171 #define TEMPHUM12_RHO_MINUS_25RH 0x80
172 
178 #define TEMPHUM12_ICFG_NORAML_OPERATION 0x00
179 #define TEMPHUM12_ICFG_SOFTWARE_RESET 0x80
180 #define TEMPHUM12_ICFG_AMM_1_120Hz 0x10
181 #define TEMPHUM12_ICFG_AMM_1_60Hz 0x20
182 #define TEMPHUM12_ICFG_AMM_0p1Hz 0x30
183 #define TEMPHUM12_ICFG_AMM_0p2Hz 0x40
184 #define TEMPHUM12_ICFG_AMM_1Hz 0x50
185 #define TEMPHUM12_ICFG_AMM_2Hz 0x60
186 #define TEMPHUM12_ICFG_AMM_5Hz 0x70
187 #define TEMPHUM12_ICFG_HEATER_DISABLE 0x00
188 #define TEMPHUM12_ICFG_HEATER_ENABLE 0x08
189 #define TEMPHUM12_ICFG_DRDY_ENABLE 0x04
190 #define TEMPHUM12_ICFG_INT_ACTIVE_LOW 0x00
191 #define TEMPHUM12_ICFG_INT_ACTIVE_HIGH 0x02
192 #define TEMPHUM12_ICFG_LEVEL_SENSITIVE 0x00
193 #define TEMPHUM12_ICFG_COMPARATOR_MODE 0x01
194 
200 #define TEMPHUM12_MCFG_TEMP_RES_14bit 0x00
201 #define TEMPHUM12_MCFG_TEMP_RES_11bit 0x40
202 #define TEMPHUM12_MCFG_TEMP_RES_8bit 0x80
203 #define TEMPHUM12_MCFG_HUM_RES_14bit 0x00
204 #define TEMPHUM12_MCFG_HUM_RES_11bit 0x10
205 #define TEMPHUM12_MCFG_HUM_RES_8bit 0x20
206 #define TEMPHUM12_MCFG_TEMP_HUM_READ 0x00
207 #define TEMPHUM12_MCFG_TEMP_ONLY 0x02
208 #define TEMPHUM12_MCFG_HUM_ONLY 0x04
209 #define TEMPHUM12_MCFG_TRIG_NO_ACTION 0x00
210 #define TEMPHUM12_MCFG_TRIG_START_MEASUREMENT 0x01
211 
217 #define TEMPHUM12_MANUFACTURER_ID 0x4954
218 #define TEMPHUM12_DEVICE_ID 0x07D0
219 #define TEMPHUM12_DEVICE_SLAVE_ADDRESS 0x40
220 
226 #define TEMPHUM12_TEMP_IN_CELSIUS 0x00
227 #define TEMPHUM12_TEMP_IN_KELVIN 0x01
228 #define TEMPHUM12_TEMP_IN_FAHRENHEIT 0x02
229  // End group macro
232 // --------------------------------------------------------------- PUBLIC TYPES
241 typedef struct
242 {
243  // Input pins
244 
245  digital_in_t int_pin;
246 
247  // Modules
248 
249  i2c_master_t i2c;
250 
251  // ctx variable
252 
253  uint8_t slave_address;
254 
255 } temphum12_t;
256 
260 typedef struct
261 {
262  // Communication gpio pins
263 
264  pin_name_t scl;
265  pin_name_t sda;
266 
267  // Additional gpio pins
268 
269  pin_name_t int_pin;
270 
271  // static variable
272 
273  uint32_t i2c_speed;
274  uint8_t i2c_address;
275 
277  // End types group
279 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
280 
286 #ifdef __cplusplus
287 extern "C"{
288 #endif
289 
299 
308 
336 
347 void temphum12_generic_write ( temphum12_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
348 
359 void temphum12_generic_read ( temphum12_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
360 
369 float temphum12_get_temperature ( temphum12_t *ctx, uint8_t temp_in );
370 
379 
388 
389 #ifdef __cplusplus
390 }
391 #endif
392 #endif // _TEMPHUM12_H_
393  // End public_function group
396 
397 // ------------------------------------------------------------------------- END
temphum12_t::int_pin
digital_in_t int_pin
Definition: temphum12.h:245
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:265
temphum12_t::slave_address
uint8_t slave_address
Definition: temphum12.h:253
temphum12_cfg_t
Click configuration structure definition.
Definition: temphum12.h:261
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:242
TEMPHUM12_RETVAL
#define TEMPHUM12_RETVAL
Definition: temphum12.h:75
temphum12_cfg_t::int_pin
pin_name_t int_pin
Definition: temphum12.h:269
temphum12_default_cfg
void temphum12_default_cfg(temphum12_t *ctx)
Click Default Configuration function.
temphum12_t::i2c
i2c_master_t i2c
Definition: temphum12.h:249
temphum12_cfg_t::scl
pin_name_t scl
Definition: temphum12.h:264
temphum12_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum12.h:274
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:273