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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define TEMPHUM3_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
56  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
57 
63 #define TEMPHUM3_RETVAL uint8_t
64 
65 #define TEMPHUM3_OK 0x00
66 #define TEMPHUM3_INIT_ERROR 0xFF
67 
73 #define TEMPHUM3_MODE_ACTIVE 0x01
74 #define TEMPHUM3_MODE_SLEEP 0x00
75 
81 #define TEMPHUM3_REG_TEMPERATURE 0x00
82 #define TEMPHUM3_REG_HUMIDITY 0x02
83 #define TEMPHUM3_REG_INTERRUPT_DRDY 0x04
84 #define TEMPHUM3_REG_TEMPERATURE_MAX 0x05
85 #define TEMPHUM3_REG_HUMIDITY_MAX 0x06
86 #define TEMPHUM3_REG_INTERRUPT_MASK 0x07
87 #define TEMPHUM3_REG_TEMP_OFFSET_ADJUST 0x08
88 #define TEMPHUM3_REG_HUM_OFFSET_ADJUST 0x09
89 #define TEMPHUM3_REG_TEMP_THRESHOLD_HIGH 0x0A
90 #define TEMPHUM3_REG_HUM_THRESHOLD_HIGH 0x0C
91 #define TEMPHUM3_REG_TEMP_THRESHOLD_LOW 0x0B
92 #define TEMPHUM3_REG_HUM_THRESHOLD_LOW 0x0D
93 #define TEMPHUM3_REG_RST_DRDY_INT_CONF 0x0E
94 #define TEMPHUM3_REG_MEASUREMENT_CONF 0x0F
95 #define TEMPHUM3_REG_MANUFACTURER_ID 0xFC
96 #define TEMPHUM3_REG_DEVICE_ID 0xFE
97 
103 #define TEMPHUM3_STATUS_DRDY 0x80
104 #define TEMPHUM3_STATUS_TEMP_HIGH 0x40
105 #define TEMPHUM3_STATUS_TEMP_LOW 0x20
106 #define TEMPHUM3_STATUS_HUM_HIGH 0x10
107 #define TEMPHUM3_STATUS_HUM_LOW 0x08
108 
114 #define TEMPHUM3_MASK_DRDY 0x80
115 #define TEMPHUM3_MASK_TEMP_HIGH 0x40
116 #define TEMPHUM3_MASK_TEMP_LOW 0x20
117 #define TEMPHUM3_MASK_HUM_HIGH 0x10
118 #define TEMPHUM3_MASK_HUM_LOW 0x08
119 
126 #define TEMPHUM3_CONF_NORMAL_MODE 0x00 << 7
127 #define TEMPHUM3_CONF_SOFT_RESET 0x01 << 7
128 
134 #define TEMPHUM3_CONF_ODR_NO_REPEATED 0x00 << 4
135 #define TEMPHUM3_CONF_ODR_REPEATED_2MIN 0x01 << 4
136 #define TEMPHUM3_CONF_ODR_REPEATED_1MIN 0x02 << 4
137 #define TEMPHUM3_CONF_ODR_REPEATED_10SEC 0x03 << 4
138 #define TEMPHUM3_CONF_ODR_REPEATED_5SEC 0x04 << 4
139 #define TEMPHUM3_CONF_ODR_REPEATED_1SEC 0x05 << 4
140 #define TEMPHUM3_CONF_ODR_REPEATED_500MS 0x06 << 4
141 #define TEMPHUM3_CONF_ODR_REPEATED_200MS 0x07 << 4
142 #define TEMPHUM3_CONF_HEATER_OFF 0x00 << 3
143 #define TEMPHUM3_CONF_HEATER_ON 0x01 << 3
144 #define TEMPHUM3_CONF_INT_DRDY_HIGH_Z 0x00 << 2
145 #define TEMPHUM3_CONF_INT_DRDY_ENABLE 0x01 << 2
146 #define TEMPHUM3_CONF_INT_POL_LOW 0x00 << 1
147 #define TEMPHUM3_CONF_INT_POL_HIGH 0x01 << 1
148 #define TEMPHUM3_CONF_INT_MODE_SENSITIVE 0x00
149 #define TEMPHUM3_CONF_INT_MODE_COMPARATOR 0x01
150 
156 #define TEMPHUM3_MCONF_TEMP_RES_14BIT 0x00 << 6
157 #define TEMPHUM3_MCONF_TEMP_RES_11BIT 0x01 << 6
158 #define TEMPHUM3_MCONF_TEMP_RES_9BIT 0x02 << 6
159 #define TEMPHUM3_MCONF_HUM_RES_14BIT 0x00 << 5
160 #define TEMPHUM3_MCONF_HUM_RES_11BIT 0x01 << 5
161 #define TEMPHUM3_MCONF_HUM_RES_9BIT 0x02 << 5
162 #define TEMPHUM3_MCONF_HUM_TEMP 0x00 << 1
163 #define TEMPHUM3_MCONF_TEMP_ONLY 0x01 << 1
164 #define TEMPHUM3_MCONF_HUM_ONLY 0x02 << 1
165 #define TEMPHUM3_MCONF_MEAS_START 0x01
166 #define TEMPHUM3_MCONF_MEAS_NO_ACTION 0x00
167  // End group macro
170 // --------------------------------------------------------------- PUBLIC TYPES
179 typedef struct
180 {
181  // Output pins
182 
183  digital_out_t cs;
184 
185  // Input pins
186 
187  digital_in_t int_pin;
188 
189  // Modules
190 
191  i2c_master_t i2c;
192 
193  // ctx variable
194 
195  uint8_t slave_address;
196 
197 } temphum3_t;
198 
202 typedef struct
203 {
204  // Communication gpio pins
205 
206  pin_name_t scl;
207  pin_name_t sda;
208 
209  // Additional gpio pins
210 
211  pin_name_t cs;
212  pin_name_t int_pin;
213 
214  // static variable
215 
216  uint32_t i2c_speed;
217  uint8_t i2c_address;
218 
220  // End types group
222 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
223 
229 #ifdef __cplusplus
230 extern "C"{
231 #endif
232 
241 void temphum3_cfg_setup ( temphum3_cfg_t *cfg );
242 
252 
260 void temphum3_default_cfg ( temphum3_t *ctx );
261 
272 void temphum3_generic_write ( temphum3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
273 
284 void temphum3_generic_read ( temphum3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
285 
294 void temphum3_set_mode ( temphum3_t *ctx, uint8_t value );
295 
304 void temphum3_set_configuration ( temphum3_t *ctx, uint8_t value );
305 
313 void temphum3_set_measurement ( temphum3_t *ctx, uint8_t value );
314 
322 float temphum3_get_temperature ( temphum3_t *ctx );
323 
331 float temphum3_get_humidity ( temphum3_t *ctx );
332 
340 uint16_t temphum3_get_id ( temphum3_t *ctx );
341 
349 uint16_t temphum3_get_manufacturer_id ( temphum3_t *ctx );
350 
358 uint8_t temphum3_get_status_interrupt ( temphum3_t *ctx, uint8_t mask );
359 
368 uint8_t temphum3_get_interrupt_mask ( temphum3_t *ctx, uint8_t mask );
369 
379 void temphum3_set_offset ( temphum3_t *ctx, uint8_t reg, uint8_t value );
380 
389 void temphum3_set_high_temp ( temphum3_t *ctx, uint8_t temp_data );
390 
399 void temphum3_set_low_temp ( temphum3_t *ctx, uint8_t temp_data);
400 
409 void temphum3_set_high_hum( temphum3_t *ctx, uint8_t hum_data);
410 
419 void temphum3_set_low_hum( temphum3_t *ctx, uint8_t hum_data);
420 
428 float temphum3_get_max_hum ( temphum3_t *ctx );
429 
437 float temphum3_get_max_temp ( temphum3_t *ctx );
438 
439 #ifdef __cplusplus
440 }
441 #endif
442 #endif // _TEMPHUM3_H_
443  // End public_function group
446 
447 // ------------------------------------------------------------------------- END
temphum3_get_id
uint16_t temphum3_get_id(temphum3_t *ctx)
Get ID function.
TEMPHUM3_RETVAL
#define TEMPHUM3_RETVAL
Definition: temphum3.h:63
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:212
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:207
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:206
temphum3_t
Click ctx object definition.
Definition: temphum3.h:179
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_get_status_interrupt
uint8_t temphum3_get_status_interrupt(temphum3_t *ctx, uint8_t mask)
Get interrupt status function.
temphum3_init
TEMPHUM3_RETVAL temphum3_init(temphum3_t *ctx, temphum3_cfg_t *cfg)
Initialization function.
temphum3_t::slave_address
uint8_t slave_address
Definition: temphum3.h:195
temphum3_t::cs
digital_out_t cs
Definition: temphum3.h:183
temphum3_t::i2c
i2c_master_t i2c
Definition: temphum3.h:191
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:202
temphum3_cfg_t::cs
pin_name_t cs
Definition: temphum3.h:211
temphum3_t::int_pin
digital_in_t int_pin
Definition: temphum3.h:187
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:216
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:217
temphum3_get_max_temp
float temphum3_get_max_temp(temphum3_t *ctx)
Get maximum temperature function.