temphum3  2.0.0.0
temphum3.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 TEMPHUM3_H
36 #define TEMPHUM3_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 // -------------------------------------------------------------- PUBLIC MACROS
62 #define TEMPHUM3_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.addr = MIKROBUS( mikrobus, MIKROBUS_CS ); \
66  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
67 
73 #define TEMPHUM3_OK 0
74 #define TEMPHUM3_ERROR -1
75 
81 #define TEMPHUM3_MODE_ACTIVE 0x01
82 #define TEMPHUM3_MODE_SLEEP 0x00
83 
89 #define TEMPHUM3_REG_TEMPERATURE 0x00
90 #define TEMPHUM3_REG_HUMIDITY 0x02
91 #define TEMPHUM3_REG_INTERRUPT_DRDY 0x04
92 #define TEMPHUM3_REG_TEMPERATURE_MAX 0x05
93 #define TEMPHUM3_REG_HUMIDITY_MAX 0x06
94 #define TEMPHUM3_REG_INTERRUPT_MASK 0x07
95 #define TEMPHUM3_REG_TEMP_OFFSET_ADJUST 0x08
96 #define TEMPHUM3_REG_HUM_OFFSET_ADJUST 0x09
97 #define TEMPHUM3_REG_TEMP_THRESHOLD_HIGH 0x0A
98 #define TEMPHUM3_REG_HUM_THRESHOLD_HIGH 0x0C
99 #define TEMPHUM3_REG_TEMP_THRESHOLD_LOW 0x0B
100 #define TEMPHUM3_REG_HUM_THRESHOLD_LOW 0x0D
101 #define TEMPHUM3_REG_RST_DRDY_INT_CONF 0x0E
102 #define TEMPHUM3_REG_MEASUREMENT_CONF 0x0F
103 #define TEMPHUM3_REG_MANUFACTURER_ID 0xFC
104 #define TEMPHUM3_REG_DEVICE_ID 0xFE
105 
111 #define TEMPHUM3_STATUS_DRDY 0x80
112 #define TEMPHUM3_STATUS_TEMP_HIGH 0x40
113 #define TEMPHUM3_STATUS_TEMP_LOW 0x20
114 #define TEMPHUM3_STATUS_HUM_HIGH 0x10
115 #define TEMPHUM3_STATUS_HUM_LOW 0x08
116 
122 #define TEMPHUM3_MASK_DRDY 0x80
123 #define TEMPHUM3_MASK_TEMP_HIGH 0x40
124 #define TEMPHUM3_MASK_TEMP_LOW 0x20
125 #define TEMPHUM3_MASK_HUM_HIGH 0x10
126 #define TEMPHUM3_MASK_HUM_LOW 0x08
127 
134 #define TEMPHUM3_CONF_NORMAL_MODE 0x00
135 #define TEMPHUM3_CONF_SOFT_RESET 0x80
136 
142 #define TEMPHUM3_CONF_ODR_NO_REPEATED 0x00
143 #define TEMPHUM3_CONF_ODR_REPEATED_2MIN 0x10
144 #define TEMPHUM3_CONF_ODR_REPEATED_1MIN 0x20
145 #define TEMPHUM3_CONF_ODR_REPEATED_10SEC 0x30
146 #define TEMPHUM3_CONF_ODR_REPEATED_5SEC 0x40
147 #define TEMPHUM3_CONF_ODR_REPEATED_1SEC 0x50
148 #define TEMPHUM3_CONF_ODR_REPEATED_500MS 0x60
149 #define TEMPHUM3_CONF_ODR_REPEATED_200MS 0x70
150 #define TEMPHUM3_CONF_HEATER_OFF 0x00
151 #define TEMPHUM3_CONF_HEATER_ON 0x08
152 #define TEMPHUM3_CONF_INT_DRDY_HIGH_Z 0x00
153 #define TEMPHUM3_CONF_INT_DRDY_ENABLE 0x04
154 #define TEMPHUM3_CONF_INT_POL_LOW 0x00
155 #define TEMPHUM3_CONF_INT_POL_HIGH 0x02
156 #define TEMPHUM3_CONF_INT_MODE_SENSITIVE 0x00
157 #define TEMPHUM3_CONF_INT_MODE_COMPARATOR 0x01
158 
164 #define TEMPHUM3_MCONF_TEMP_RES_14BIT 0x00
165 #define TEMPHUM3_MCONF_TEMP_RES_11BIT 0x40
166 #define TEMPHUM3_MCONF_TEMP_RES_9BIT 0x80
167 #define TEMPHUM3_MCONF_HUM_RES_14BIT 0x00
168 #define TEMPHUM3_MCONF_HUM_RES_11BIT 0x10
169 #define TEMPHUM3_MCONF_HUM_RES_9BIT 0x20
170 #define TEMPHUM3_MCONF_HUM_TEMP 0x00
171 #define TEMPHUM3_MCONF_TEMP_ONLY 0x02
172 #define TEMPHUM3_MCONF_HUM_ONLY 0x04
173 #define TEMPHUM3_MCONF_MEAS_START 0x01
174 #define TEMPHUM3_MCONF_MEAS_NO_ACTION 0x00
175  // End group macro
178 // --------------------------------------------------------------- PUBLIC TYPES
187 typedef struct
188 {
189  // Output pins
190  digital_out_t addr;
191 
192  // Input pins
193  digital_in_t int_pin;
194 
195  // Modules
196  i2c_master_t i2c;
197 
198  // ctx variable
199  uint8_t slave_address;
200 
201 } temphum3_t;
202 
206 typedef struct
207 {
208  // Communication gpio pins
209  pin_name_t scl;
210  pin_name_t sda;
211 
212  // Additional gpio pins
213  pin_name_t addr;
214  pin_name_t int_pin;
215 
216  // static variable
217  uint32_t i2c_speed;
218  uint8_t i2c_address;
219 
221  // End types group
223 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
224 
230 #ifdef __cplusplus
231 extern "C"{
232 #endif
233 
243 
253 
262 
273 void temphum3_generic_write ( temphum3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
274 
285 void temphum3_generic_read ( temphum3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
286 
295 void temphum3_set_mode ( temphum3_t *ctx, uint8_t value );
296 
305 void temphum3_set_configuration ( temphum3_t *ctx, uint8_t value );
306 
314 void temphum3_set_measurement ( temphum3_t *ctx, uint8_t value );
315 
324 
333 
341 uint16_t temphum3_get_id ( temphum3_t *ctx );
342 
351 
359 uint8_t temphum3_get_status_interrupt ( temphum3_t *ctx, uint8_t mask );
360 
369 uint8_t temphum3_get_interrupt_mask ( temphum3_t *ctx, uint8_t mask );
370 
380 void temphum3_set_offset ( temphum3_t *ctx, uint8_t reg, uint8_t value );
381 
390 void temphum3_set_high_temp ( temphum3_t *ctx, uint8_t temp_data );
391 
400 void temphum3_set_low_temp ( temphum3_t *ctx, uint8_t temp_data );
401 
410 void temphum3_set_high_hum( temphum3_t *ctx, uint8_t hum_data );
411 
420 void temphum3_set_low_hum( temphum3_t *ctx, uint8_t hum_data );
421 
430 
439 
440 #ifdef __cplusplus
441 }
442 #endif
443 #endif // _TEMPHUM3_H_
444  // End public_function group
447 
448 // ------------------------------------------------------------------------- END
temphum3_get_id
uint16_t temphum3_get_id(temphum3_t *ctx)
Get ID function.
temphum3_get_max_hum
float temphum3_get_max_hum(temphum3_t *ctx)
Get maximum humidity function.
temphum3_cfg_t::int_pin
pin_name_t int_pin
Definition: temphum3.h:214
temphum3_set_low_temp
void temphum3_set_low_temp(temphum3_t *ctx, uint8_t temp_data)
Set low temperature function.
temphum3_set_mode
void temphum3_set_mode(temphum3_t *ctx, uint8_t value)
Set measurement mode function.
temphum3_cfg_t::sda
pin_name_t sda
Definition: temphum3.h:210
temphum3_set_measurement
void temphum3_set_measurement(temphum3_t *ctx, uint8_t value)
Set measurement function.
temphum3_get_humidity
float temphum3_get_humidity(temphum3_t *ctx)
Get humidity function.
temphum3_set_configuration
void temphum3_set_configuration(temphum3_t *ctx, uint8_t value)
Set configuration function.
temphum3_set_low_hum
void temphum3_set_low_hum(temphum3_t *ctx, uint8_t hum_data)
Set low humidity function.
temphum3_cfg_t::scl
pin_name_t scl
Definition: temphum3.h:209
temphum3_t
Click ctx object definition.
Definition: temphum3.h:188
temphum3_get_interrupt_mask
uint8_t temphum3_get_interrupt_mask(temphum3_t *ctx, uint8_t mask)
Get interrupt mask function.
temphum3_get_temperature
float temphum3_get_temperature(temphum3_t *ctx)
Get temperature function.
temphum3_generic_write
void temphum3_generic_write(temphum3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
temphum3_cfg_t::addr
pin_name_t addr
Definition: temphum3.h:213
temphum3_get_status_interrupt
uint8_t temphum3_get_status_interrupt(temphum3_t *ctx, uint8_t mask)
Get interrupt status function.
temphum3_t::slave_address
uint8_t slave_address
Definition: temphum3.h:199
temphum3_t::i2c
i2c_master_t i2c
Definition: temphum3.h:196
temphum3_set_high_temp
void temphum3_set_high_temp(temphum3_t *ctx, uint8_t temp_data)
Set high temperature function.
temphum3_generic_read
void temphum3_generic_read(temphum3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
temphum3_get_manufacturer_id
uint16_t temphum3_get_manufacturer_id(temphum3_t *ctx)
Get manufacturer's ID function.
temphum3_cfg_t
Click configuration structure definition.
Definition: temphum3.h:207
temphum3_t::int_pin
digital_in_t int_pin
Definition: temphum3.h:193
temphum3_init
err_t temphum3_init(temphum3_t *ctx, temphum3_cfg_t *cfg)
Initialization function.
temphum3_cfg_setup
void temphum3_cfg_setup(temphum3_cfg_t *cfg)
Config Object Initialization function.
temphum3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum3.h:217
temphum3_t::addr
digital_out_t addr
Definition: temphum3.h:190
temphum3_default_cfg
void temphum3_default_cfg(temphum3_t *ctx)
Click Default Configuration function.
temphum3_set_offset
void temphum3_set_offset(temphum3_t *ctx, uint8_t reg, uint8_t value)
Set offset function.
temphum3_set_high_hum
void temphum3_set_high_hum(temphum3_t *ctx, uint8_t hum_data)
Set high humidity function.
temphum3_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum3.h:218
temphum3_get_max_temp
float temphum3_get_max_temp(temphum3_t *ctx)
Get maximum temperature function.