temphum  2.0.0.0
temphum.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef TEMPHIM_H
36 #define TEMPHIM_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define TEMPHIM_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
57 
63 #define TEMPHIM_RETVAL uint8_t
64 
65 #define TEMPHIM_OK 0x00
66 #define TEMPHIM_INIT_ERROR 0xFF
67 
73 #define TEMPANDHUM_I2C_ADDRESS 0x5F
74 
80 #define TEMPANDHUM_WHO_AM_I 0x0F
81 #define TEMPANDHUM_AV_CONF 0x10
82 #define TEMPANDHUM_CTRL_REG1 0x20
83 #define TEMPANDHUM_CTRL_REG2 0x21
84 #define TEMPANDHUM_CTRL_REG3 0x22
85 #define TEMPANDHUM_STATUS_REG 0x27
86 #define TEMPANDHUM_HUMIDITY_OUT_L 0x28
87 #define TEMPANDHUM_HUMIDITY_OUT_H 0x29
88 #define TEMPANDHUM_TEMP_OUT_L 0x2A
89 #define TEMPANDHUM_TEMP_OUT_H 0x2B
90 #define TEMPANDHUM_H0_RH_X2 0x30
91 #define TEMPANDHUM_H1_RH_X2 0x31
92 #define TEMPANDHUM_T0_DEGC_X8 0x32
93 #define TEMPANDHUM_T1_DEGC_X8 0x33
94 #define TEMPANDHUM_T1_T0_MSB 0x35
95 #define TEMPANDHUM_H0_T0_OUT_L 0x36
96 #define TEMPANDHUM_H0_T0_OUT_H 0x37
97 #define TEMPANDHUM_H1_T0_OUT_L 0x3A
98 #define TEMPANDHUM_H1_T0_OUT_H 0x3B
99 #define TEMPANDHUM_T0_OUT_L 0x3C
100 #define TEMPANDHUM_T0_OUT_H 0x3D
101 #define TEMPANDHUM_T1_OUT_L 0x3E
102 #define TEMPANDHUM_T1_OUT_H 0x3F
103 
109 #define TEMPANDHUM_AV_CONF_DEFAULT_VALUE 0x1B
110 #define TEMPANDHUM_CTRL_REG1_DEFAULT_VALUE 0x85
111 #define TEMPANDHUM_CTRL_REG2_DEFAULT_VALUE 0x00
112 #define TEMPANDHUM_CTRL_REG3_DEFAULT_VALUE 0x00
113  // End group macro
116 // --------------------------------------------------------------- PUBLIC TYPES
125 typedef struct
126 {
127  // Input pins
128 
129  digital_in_t int_pin;
130 
131  // Modules
132 
133  i2c_master_t i2c;
134 
135  // ctx variable
136 
137  hal_i2c_address_t slave_address;
138 
139  float float_h_out;
140  float float_t_out;
141  uint8_t h0_rh_x2;
142  uint8_t h1_rh_x2;
143  uint8_t t0_deg_c_x8;
144  uint8_t t1_deg_c_x8;
145  int16_t h0_t0_out;
146  int16_t h1_t0_out;
147  int16_t t0_out;
148  int16_t t1_out;
151  float h0_rh_cal;
152  float h1_rh_cal;
153 
154 } temphum_t;
155 
159 typedef struct
160 {
161  // Communication gpio pins
162 
163  pin_name_t scl;
164  pin_name_t sda;
165 
166  // Additional gpio pins
167 
168  pin_name_t int_pin;
169 
170  // static variable
171 
172  hal_i2c_speed_t i2c_speed;
173  hal_i2c_address_t i2c_address;
174 
175 } temphum_cfg_t;
176 
177 
178  // End types group
180 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
181 
187 #ifdef __cplusplus
188 extern "C"{
189 #endif
190 
199 void temphum_cfg_setup ( temphum_cfg_t *cfg );
200 
209 
217 void temphum_default_cfg ( temphum_t *ctx );
218 
229 void temphum_generic_write ( temphum_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
230 
242 void temphum_generic_read ( temphum_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
243 
254 uint16_t temphum_get_hum_data ( temphum_t *ctx );
255 
266 uint16_t temphum_get_temp_data( temphum_t *ctx );
267 
280 void temphum_get_temp_hum ( temphum_t *ctx, float *temperature, float *humidity );
281 
292 float temphum_get_temperature( temphum_t *ctx );
293 
304 float temphum_get_humidity( temphum_t *ctx );
305 
306 #ifdef __cplusplus
307 }
308 #endif
309 #endif // _TEMPHIM_H_
310  // End public_function group
313 
314 // ------------------------------------------------------------------------- END
Click configuration structure definition.
Definition: temphum.h:159
float temphum_get_temperature(temphum_t *ctx)
Gets temperature in degrees Celsius function.
uint8_t t1_deg_c_x8
Definition: temphum.h:144
void temphum_cfg_setup(temphum_cfg_t *cfg)
Config Object Initialization function.
Click ctx object definition.
Definition: temphum.h:125
float t1_deg_c_cal
Definition: temphum.h:150
i2c_master_t i2c
Definition: temphum.h:133
hal_i2c_speed_t i2c_speed
Definition: temphum.h:172
void temphum_generic_write(temphum_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint8_t t0_deg_c_x8
Definition: temphum.h:143
hal_i2c_address_t i2c_address
Definition: temphum.h:173
pin_name_t sda
Definition: temphum.h:164
int16_t t1_out
Definition: temphum.h:148
uint8_t h0_rh_x2
Definition: temphum.h:141
float h0_rh_cal
Definition: temphum.h:151
#define TEMPHIM_RETVAL
Definition: temphum.h:63
hal_i2c_address_t slave_address
Definition: temphum.h:137
float float_t_out
Definition: temphum.h:140
float float_h_out
Definition: temphum.h:139
pin_name_t int_pin
Definition: temphum.h:168
void temphum_default_cfg(temphum_t *ctx)
Click Default Configuration function.
float temphum_get_humidity(temphum_t *ctx)
Gets humidity in degrees Celsius function.
void temphum_generic_read(temphum_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
float h1_rh_cal
Definition: temphum.h:152
int16_t h0_t0_out
Definition: temphum.h:145
uint16_t temphum_get_hum_data(temphum_t *ctx)
Gets humidity data function.
TEMPHIM_RETVAL temphum_init(temphum_t *ctx, temphum_cfg_t *cfg)
Initialization function.
float t0_deg_c_cal
Definition: temphum.h:149
pin_name_t scl
Definition: temphum.h:163
int16_t t0_out
Definition: temphum.h:147
uint16_t temphum_get_temp_data(temphum_t *ctx)
Gets temperature data function.
void temphum_get_temp_hum(temphum_t *ctx, float *temperature, float *humidity)
Gets temperature and humidity function.
int16_t h1_t0_out
Definition: temphum.h:146
uint8_t h1_rh_x2
Definition: temphum.h:142
digital_in_t int_pin
Definition: temphum.h:129