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 "drv_digital_in.h"
39 #include "drv_i2c_master.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define TEMPHUM12_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
53  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
54  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
55 
61 #define TEMPHUM12_RETVAL uint8_t
62 
63 #define TEMPHUM12_OK 0x00
64 #define TEMPHUM12_INIT_ERROR 0xFF
65 
71 #define TEMPHUM12_REG_TEMPERATURE_LSB 0x00
72 #define TEMPHUM12_REG_TEMPERATURE_MSB 0x01
73 #define TEMPHUM12_REG_HUMIDITY_LSB 0x02
74 #define TEMPHUM12_REG_HUMIDITY_MSB 0x03
75 #define TEMPHUM12_REG_DRDY_INTERRUPT 0x04
76 #define TEMPHUM12_REG_TEMP_MAX 0x05
77 #define TEMPHUM12_REG_HUM_MAX 0x06
78 #define TEMPHUM12_REG_INT_ENABLE 0x07
79 #define TEMPHUM12_REG_TEMP_OFFSET 0x08
80 #define TEMPHUM12_REG_HUM_OFFSET 0x09
81 #define TEMPHUM12_REG_TEMP_THR_LSB 0x0A
82 #define TEMPHUM12_REG_TEMP_THR_MSB 0x0B
83 #define TEMPHUM12_REG_HUM_THR_LSB 0x0C
84 #define TEMPHUM12_REG_HUM_THR_MSB 0x0D
85 #define TEMPHUM12_REG_DRDY_INT_CONFIG 0x0E
86 #define TEMPHUM12_REG_CONFIGURATION 0x0F
87 #define TEMPHUM12_REG_MANUFACTURER_ID_LSB 0xFC
88 #define TEMPHUM12_REG_MANUFACTURER_ID_MSB 0xFD
89 #define TEMPHUM12_REG_DEVICE_ID_LSB 0xFE
90 #define TEMPHUM12_REG_DEVICE_ID_MSB 0xFF
91 
97 #define TEMPHUM12_REG_DATA_TEMPERATURE 0x00
98 #define TEMPHUM12_REG_DATA_HUMIDITY 0x02
99 #define TEMPHUM12_REG_DATA_TEMP_THR 0x0A
100 #define TEMPHUM12_REG_DATA_HUM_THR 0x0C
101 #define TEMPHUM12_REG_DATA_MANUFACTURER_ID 0xFC
102 #define TEMPHUM12_REG_DATA_DEVICE_ID 0xFE
103 
109 #define TEMPHUM12_INT_STATUS_DRDY 0x80
110 #define TEMPHUM12_INT_STATUS_TEMP_THR_HIGH 0x40
111 #define TEMPHUM12_INT_STATUS_TEMP_THR_LOW 0x20
112 #define TEMPHUM12_INT_STATUS_HUM_THR_HIGH 0x10
113 #define TEMPHUM12_INT_STATUS_HUM_THR_LOW 0x08
114 
120 #define TEMPHUM12_INTE_DRDY_ENABLE 0x80
121 #define TEMPHUM12_INTE_DRDY_DISABLE 0x00
122 #define TEMPHUM12_INTE_TEMP_TH_ENABLE 0x40
123 #define TEMPHUM12_INTE_TEMP_TH_DISABLE 0x00
124 #define TEMPHUM12_INTE_TEMP_TL_ENABLE 0x20
125 #define TEMPHUM12_INTE_TEMP_TL_DISABLE 0x00
126 #define TEMPHUM12_INTE_HUM_TH_ENABLE 0x10
127 #define TEMPHUM12_INTE_HUM_TH_DISABLE 0x00
128 #define TEMPHUM12_INTE_HUM_TL_ENABLE 0x08
129 #define TEMPHUM12_INTE_HUM_TL_DISABLE 0x00
130 
136 #define TEMPHUM12_TO_PLUS_0_16C 0x01
137 #define TEMPHUM12_TO_PLUS_0_32C 0x02
138 #define TEMPHUM12_TO_PLUS_0_64C 0x04
139 #define TEMPHUM12_TO_PLUS_1_28C 0x08
140 #define TEMPHUM12_TO_PLUS_2_58C 0x10
141 #define TEMPHUM12_TO_PLUS_5_16C 0x20
142 #define TEMPHUM12_TO_PLUS_10_32C 0x40
143 #define TEMPHUM12_TO_MINUS_20_62C 0x80
144 
150 #define TEMPHUM12_RHO_PLUS_0_2RH 0x01
151 #define TEMPHUM12_RHO_PLUS_0_4RH 0x02
152 #define TEMPHUM12_RHO_PLUS_0_8RH 0x04
153 #define TEMPHUM12_RHO_PLUS_1_6RH 0x08
154 #define TEMPHUM12_RHO_PLUS_3_1RH 0x10
155 #define TEMPHUM12_RHO_PLUS_6_3RH 0x20
156 #define TEMPHUM12_RHO_PLUS_12_5RH 0x40
157 #define TEMPHUM12_RHO_MINUS_25RH 0x80
158 
164 #define TEMPHUM12_ICFG_NORAML_OPERATION 0x00
165 #define TEMPHUM12_ICFG_SOFTWARE_RESET 0x80
166 #define TEMPHUM12_ICFG_AMM_1_120Hz 0x10
167 #define TEMPHUM12_ICFG_AMM_1_60Hz 0x20
168 #define TEMPHUM12_ICFG_AMM_0p1Hz 0x30
169 #define TEMPHUM12_ICFG_AMM_0p2Hz 0x40
170 #define TEMPHUM12_ICFG_AMM_1Hz 0x50
171 #define TEMPHUM12_ICFG_AMM_2Hz 0x60
172 #define TEMPHUM12_ICFG_AMM_5Hz 0x70
173 #define TEMPHUM12_ICFG_HEATER_DISABLE 0x00
174 #define TEMPHUM12_ICFG_HEATER_ENABLE 0x08
175 #define TEMPHUM12_ICFG_DRDY_ENABLE 0x04
176 #define TEMPHUM12_ICFG_INT_ACTIVE_LOW 0x00
177 #define TEMPHUM12_ICFG_INT_ACTIVE_HIGH 0x02
178 #define TEMPHUM12_ICFG_LEVEL_SENSITIVE 0x00
179 #define TEMPHUM12_ICFG_COMPARATOR_MODE 0x01
180 
186 #define TEMPHUM12_MCFG_TEMP_RES_14bit 0x00
187 #define TEMPHUM12_MCFG_TEMP_RES_11bit 0x40
188 #define TEMPHUM12_MCFG_TEMP_RES_8bit 0x80
189 #define TEMPHUM12_MCFG_HUM_RES_14bit 0x00
190 #define TEMPHUM12_MCFG_HUM_RES_11bit 0x10
191 #define TEMPHUM12_MCFG_HUM_RES_8bit 0x20
192 #define TEMPHUM12_MCFG_TEMP_HUM_READ 0x00
193 #define TEMPHUM12_MCFG_TEMP_ONLY 0x02
194 #define TEMPHUM12_MCFG_HUM_ONLY 0x04
195 #define TEMPHUM12_MCFG_TRIG_NO_ACTION 0x00
196 #define TEMPHUM12_MCFG_TRIG_START_MEASUREMENT 0x01
197 
203 #define TEMPHUM12_MANUFACTURER_ID 0x4954
204 #define TEMPHUM12_DEVICE_ID 0x07D0
205 #define TEMPHUM12_DEVICE_SLAVE_ADDRESS 0x40
206 
212 #define TEMPHUM12_TEMP_IN_CELSIUS 0x00
213 #define TEMPHUM12_TEMP_IN_KELVIN 0x01
214 #define TEMPHUM12_TEMP_IN_FAHRENHEIT 0x02
215  // End group macro
218 // --------------------------------------------------------------- PUBLIC TYPES
227 typedef struct
228 {
229  // Input pins
230 
231  digital_in_t int_pin;
232 
233  // Modules
234 
235  i2c_master_t i2c;
236 
237  // ctx variable
238 
239  uint8_t slave_address;
240 
241 } temphum12_t;
242 
246 typedef struct
247 {
248  // Communication gpio pins
249 
250  pin_name_t scl;
251  pin_name_t sda;
252 
253  // Additional gpio pins
254 
255  pin_name_t int_pin;
256 
257  // static variable
258 
259  uint32_t i2c_speed;
260  uint8_t i2c_address;
261 
263  // End types group
265 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
266 
272 #ifdef __cplusplus
273 extern "C"{
274 #endif
275 
285 
294 
321 void temphum12_default_cfg ( temphum12_t *ctx );
322 
333 void temphum12_generic_write ( temphum12_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
334 
345 void temphum12_generic_read ( temphum12_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
346 
355 float temphum12_get_temperature ( temphum12_t *ctx, uint8_t temp_in );
356 
364 float temphum12_get_humidity ( temphum12_t *ctx );
365 
374 
375 #ifdef __cplusplus
376 }
377 #endif
378 #endif // _TEMPHUM12_H_
379  // End public_function group
382 
383 // ------------------------------------------------------------------------- END
temphum12_t::int_pin
digital_in_t int_pin
Definition: temphum12.h:231
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:251
temphum12_t::slave_address
uint8_t slave_address
Definition: temphum12.h:239
temphum12_cfg_t
Click configuration structure definition.
Definition: temphum12.h:246
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:227
TEMPHUM12_RETVAL
#define TEMPHUM12_RETVAL
Definition: temphum12.h:61
temphum12_cfg_t::int_pin
pin_name_t int_pin
Definition: temphum12.h:255
temphum12_default_cfg
void temphum12_default_cfg(temphum12_t *ctx)
Click Default Configuration function.
temphum12_t::i2c
i2c_master_t i2c
Definition: temphum12.h:235
temphum12_cfg_t::scl
pin_name_t scl
Definition: temphum12.h:250
temphum12_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum12.h:260
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:259