temphum  2.0.0.0
temphum.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 TEMPHIM_H
36 #define TEMPHIM_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_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define TEMPHIM_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
65  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
66  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
67 
73 #define TEMPHIM_RETVAL uint8_t
74 
75 #define TEMPHIM_OK 0x00
76 #define TEMPHIM_INIT_ERROR 0xFF
77 
83 #define TEMPANDHUM_I2C_ADDRESS 0x5F
84 
90 #define TEMPANDHUM_WHO_AM_I 0x0F
91 #define TEMPANDHUM_AV_CONF 0x10
92 #define TEMPANDHUM_CTRL_REG1 0x20
93 #define TEMPANDHUM_CTRL_REG2 0x21
94 #define TEMPANDHUM_CTRL_REG3 0x22
95 #define TEMPANDHUM_STATUS_REG 0x27
96 #define TEMPANDHUM_HUMIDITY_OUT_L 0x28
97 #define TEMPANDHUM_HUMIDITY_OUT_H 0x29
98 #define TEMPANDHUM_TEMP_OUT_L 0x2A
99 #define TEMPANDHUM_TEMP_OUT_H 0x2B
100 #define TEMPANDHUM_H0_RH_X2 0x30
101 #define TEMPANDHUM_H1_RH_X2 0x31
102 #define TEMPANDHUM_T0_DEGC_X8 0x32
103 #define TEMPANDHUM_T1_DEGC_X8 0x33
104 #define TEMPANDHUM_T1_T0_MSB 0x35
105 #define TEMPANDHUM_H0_T0_OUT_L 0x36
106 #define TEMPANDHUM_H0_T0_OUT_H 0x37
107 #define TEMPANDHUM_H1_T0_OUT_L 0x3A
108 #define TEMPANDHUM_H1_T0_OUT_H 0x3B
109 #define TEMPANDHUM_T0_OUT_L 0x3C
110 #define TEMPANDHUM_T0_OUT_H 0x3D
111 #define TEMPANDHUM_T1_OUT_L 0x3E
112 #define TEMPANDHUM_T1_OUT_H 0x3F
113 
119 #define TEMPANDHUM_AV_CONF_DEFAULT_VALUE 0x1B
120 #define TEMPANDHUM_CTRL_REG1_DEFAULT_VALUE 0x85
121 #define TEMPANDHUM_CTRL_REG2_DEFAULT_VALUE 0x00
122 #define TEMPANDHUM_CTRL_REG3_DEFAULT_VALUE 0x00
123  // End group macro
126 // --------------------------------------------------------------- PUBLIC TYPES
135 typedef struct
136 {
137  // Input pins
138 
139  digital_in_t int_pin;
140 
141  // Modules
142 
143  i2c_master_t i2c;
144 
145  // ctx variable
146 
147  uint8_t slave_address;
148 
149  float float_h_out;
150  float float_t_out;
151  uint8_t h0_rh_x2;
152  uint8_t h1_rh_x2;
153  uint8_t t0_deg_c_x8;
154  uint8_t t1_deg_c_x8;
155  int16_t h0_t0_out;
156  int16_t h1_t0_out;
157  int16_t t0_out;
158  int16_t t1_out;
161  float h0_rh_cal;
162  float h1_rh_cal;
163 
164 } temphum_t;
165 
169 typedef struct
170 {
171  // Communication gpio pins
172 
173  pin_name_t scl;
174  pin_name_t sda;
175 
176  // Additional gpio pins
177 
178  pin_name_t int_pin;
179 
180  // static variable
181 
182  uint32_t i2c_speed;
183  uint8_t i2c_address;
184 
185 } temphum_cfg_t;
186  // End types group
188 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
189 
195 #ifdef __cplusplus
196 extern "C"{
197 #endif
198 
208 
218 
227 
238 void temphum_generic_write ( temphum_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
239 
250 void temphum_generic_read ( temphum_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
251 
262 uint16_t temphum_get_hum_data ( temphum_t *ctx );
263 
275 
288 void temphum_get_temp_hum ( temphum_t *ctx, float *temperature, float *humidity );
289 
301 
313 
314 #ifdef __cplusplus
315 }
316 #endif
317 #endif // _TEMPHIM_H_
318  // End public_function group
321 
322 // ------------------------------------------------------------------------- END
temphum_default_cfg
void temphum_default_cfg(temphum_t *ctx)
Click Default Configuration function.
temphum_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum.h:183
temphum_t::h1_t0_out
int16_t h1_t0_out
Definition: temphum.h:156
temphum_t::t1_deg_c_x8
uint8_t t1_deg_c_x8
Definition: temphum.h:154
temphum_get_temp_hum
void temphum_get_temp_hum(temphum_t *ctx, float *temperature, float *humidity)
Gets temperature and humidity function.
temphum_t::t1_deg_c_cal
float t1_deg_c_cal
Definition: temphum.h:160
temphum_t::t0_deg_c_x8
uint8_t t0_deg_c_x8
Definition: temphum.h:153
TEMPHIM_RETVAL
#define TEMPHIM_RETVAL
Definition: temphum.h:73
temphum_cfg_t::sda
pin_name_t sda
Definition: temphum.h:174
temphum_get_temperature
float temphum_get_temperature(temphum_t *ctx)
Gets temperature in degrees Celsius function.
temphum_t::i2c
i2c_master_t i2c
Definition: temphum.h:143
temphum_t::t1_out
int16_t t1_out
Definition: temphum.h:158
temphum_t::float_t_out
float float_t_out
Definition: temphum.h:150
temphum_t::h0_rh_cal
float h0_rh_cal
Definition: temphum.h:161
temphum_cfg_t
Click configuration structure definition.
Definition: temphum.h:170
temphum_t::h0_rh_x2
uint8_t h0_rh_x2
Definition: temphum.h:151
temphum_t::float_h_out
float float_h_out
Definition: temphum.h:149
temphum_get_humidity
float temphum_get_humidity(temphum_t *ctx)
Gets humidity in degrees Celsius function.
temphum_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum.h:182
temphum_cfg_t::int_pin
pin_name_t int_pin
Definition: temphum.h:178
temphum_cfg_setup
void temphum_cfg_setup(temphum_cfg_t *cfg)
Config Object Initialization function.
temphum_get_temp_data
uint16_t temphum_get_temp_data(temphum_t *ctx)
Gets temperature data function.
temphum_generic_read
void temphum_generic_read(temphum_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
temphum_get_hum_data
uint16_t temphum_get_hum_data(temphum_t *ctx)
Gets humidity data function.
temphum_t::slave_address
uint8_t slave_address
Definition: temphum.h:147
temphum_generic_write
void temphum_generic_write(temphum_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
temphum_t::h1_rh_cal
float h1_rh_cal
Definition: temphum.h:162
temphum_t::h1_rh_x2
uint8_t h1_rh_x2
Definition: temphum.h:152
temphum_init
TEMPHIM_RETVAL temphum_init(temphum_t *ctx, temphum_cfg_t *cfg)
Initialization function.
temphum_t::h0_t0_out
int16_t h0_t0_out
Definition: temphum.h:155
temphum_t::t0_out
int16_t t0_out
Definition: temphum.h:157
temphum_t::int_pin
digital_in_t int_pin
Definition: temphum.h:139
temphum_t
Click ctx object definition.
Definition: temphum.h:136
temphum_cfg_t::scl
pin_name_t scl
Definition: temphum.h:173
temphum_t::t0_deg_c_cal
float t0_deg_c_cal
Definition: temphum.h:159