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
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define TEMPHUM3_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.addr = MIKROBUS( mikrobus, MIKROBUS_CS ); \
70 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
77#define TEMPHUM3_OK 0
78#define TEMPHUM3_ERROR -1
85#define TEMPHUM3_MODE_ACTIVE 0x01
86#define TEMPHUM3_MODE_SLEEP 0x00
93#define TEMPHUM3_REG_TEMPERATURE 0x00
94#define TEMPHUM3_REG_HUMIDITY 0x02
95#define TEMPHUM3_REG_INTERRUPT_DRDY 0x04
96#define TEMPHUM3_REG_TEMPERATURE_MAX 0x05
97#define TEMPHUM3_REG_HUMIDITY_MAX 0x06
98#define TEMPHUM3_REG_INTERRUPT_MASK 0x07
99#define TEMPHUM3_REG_TEMP_OFFSET_ADJUST 0x08
100#define TEMPHUM3_REG_HUM_OFFSET_ADJUST 0x09
101#define TEMPHUM3_REG_TEMP_THRESHOLD_HIGH 0x0A
102#define TEMPHUM3_REG_HUM_THRESHOLD_HIGH 0x0C
103#define TEMPHUM3_REG_TEMP_THRESHOLD_LOW 0x0B
104#define TEMPHUM3_REG_HUM_THRESHOLD_LOW 0x0D
105#define TEMPHUM3_REG_RST_DRDY_INT_CONF 0x0E
106#define TEMPHUM3_REG_MEASUREMENT_CONF 0x0F
107#define TEMPHUM3_REG_MANUFACTURER_ID 0xFC
108#define TEMPHUM3_REG_DEVICE_ID 0xFE
115#define TEMPHUM3_STATUS_DRDY 0x80
116#define TEMPHUM3_STATUS_TEMP_HIGH 0x40
117#define TEMPHUM3_STATUS_TEMP_LOW 0x20
118#define TEMPHUM3_STATUS_HUM_HIGH 0x10
119#define TEMPHUM3_STATUS_HUM_LOW 0x08
126#define TEMPHUM3_MASK_DRDY 0x80
127#define TEMPHUM3_MASK_TEMP_HIGH 0x40
128#define TEMPHUM3_MASK_TEMP_LOW 0x20
129#define TEMPHUM3_MASK_HUM_HIGH 0x10
130#define TEMPHUM3_MASK_HUM_LOW 0x08
138#define TEMPHUM3_CONF_NORMAL_MODE 0x00
139#define TEMPHUM3_CONF_SOFT_RESET 0x80
146#define TEMPHUM3_CONF_ODR_NO_REPEATED 0x00
147#define TEMPHUM3_CONF_ODR_REPEATED_2MIN 0x10
148#define TEMPHUM3_CONF_ODR_REPEATED_1MIN 0x20
149#define TEMPHUM3_CONF_ODR_REPEATED_10SEC 0x30
150#define TEMPHUM3_CONF_ODR_REPEATED_5SEC 0x40
151#define TEMPHUM3_CONF_ODR_REPEATED_1SEC 0x50
152#define TEMPHUM3_CONF_ODR_REPEATED_500MS 0x60
153#define TEMPHUM3_CONF_ODR_REPEATED_200MS 0x70
154#define TEMPHUM3_CONF_HEATER_OFF 0x00
155#define TEMPHUM3_CONF_HEATER_ON 0x08
156#define TEMPHUM3_CONF_INT_DRDY_HIGH_Z 0x00
157#define TEMPHUM3_CONF_INT_DRDY_ENABLE 0x04
158#define TEMPHUM3_CONF_INT_POL_LOW 0x00
159#define TEMPHUM3_CONF_INT_POL_HIGH 0x02
160#define TEMPHUM3_CONF_INT_MODE_SENSITIVE 0x00
161#define TEMPHUM3_CONF_INT_MODE_COMPARATOR 0x01
168#define TEMPHUM3_MCONF_TEMP_RES_14BIT 0x00
169#define TEMPHUM3_MCONF_TEMP_RES_11BIT 0x40
170#define TEMPHUM3_MCONF_TEMP_RES_9BIT 0x80
171#define TEMPHUM3_MCONF_HUM_RES_14BIT 0x00
172#define TEMPHUM3_MCONF_HUM_RES_11BIT 0x10
173#define TEMPHUM3_MCONF_HUM_RES_9BIT 0x20
174#define TEMPHUM3_MCONF_HUM_TEMP 0x00
175#define TEMPHUM3_MCONF_TEMP_ONLY 0x02
176#define TEMPHUM3_MCONF_HUM_ONLY 0x04
177#define TEMPHUM3_MCONF_MEAS_START 0x01
178#define TEMPHUM3_MCONF_MEAS_NO_ACTION 0x00
181 // End group macro
182// --------------------------------------------------------------- PUBLIC TYPES
191typedef struct
192{
193 // Output pins
194 digital_out_t addr;
195
196 // Input pins
197 digital_in_t int_pin;
198
199 // Modules
200 i2c_master_t i2c;
201
202 // ctx variable
204
205} temphum3_t;
206
210typedef struct
211{
212 // Communication gpio pins
213 pin_name_t scl;
214 pin_name_t sda;
215
216 // Additional gpio pins
217 pin_name_t addr;
218 pin_name_t int_pin;
219
220 // static variable
221 uint32_t i2c_speed;
222 uint8_t i2c_address;
223
225
226 // End types group
227// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
228
234#ifdef __cplusplus
235extern "C"{
236#endif
237
247
257
266
277void temphum3_generic_write ( temphum3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
278
289void temphum3_generic_read ( temphum3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
290
299void temphum3_set_mode ( temphum3_t *ctx, uint8_t value );
300
309void temphum3_set_configuration ( temphum3_t *ctx, uint8_t value );
310
318void temphum3_set_measurement ( temphum3_t *ctx, uint8_t value );
319
328
337
345uint16_t temphum3_get_id ( temphum3_t *ctx );
346
355
363uint8_t temphum3_get_status_interrupt ( temphum3_t *ctx, uint8_t mask );
364
373uint8_t temphum3_get_interrupt_mask ( temphum3_t *ctx, uint8_t mask );
374
384void temphum3_set_offset ( temphum3_t *ctx, uint8_t reg, uint8_t value );
385
394void temphum3_set_high_temp ( temphum3_t *ctx, uint8_t temp_data );
395
404void temphum3_set_low_temp ( temphum3_t *ctx, uint8_t temp_data );
405
414void temphum3_set_high_hum( temphum3_t *ctx, uint8_t hum_data );
415
424void temphum3_set_low_hum( temphum3_t *ctx, uint8_t hum_data );
425
434
443
444#ifdef __cplusplus
445}
446#endif
447#endif // _TEMPHUM3_H_
448
449 // End public_function group
451
452// ------------------------------------------------------------------------- END
void temphum3_set_high_temp(temphum3_t *ctx, uint8_t temp_data)
Set high temperature function.
void temphum3_set_low_temp(temphum3_t *ctx, uint8_t temp_data)
Set low temperature function.
float temphum3_get_temperature(temphum3_t *ctx)
Get temperature function.
void temphum3_set_high_hum(temphum3_t *ctx, uint8_t hum_data)
Set high humidity function.
uint16_t temphum3_get_id(temphum3_t *ctx)
Get ID function.
float temphum3_get_max_hum(temphum3_t *ctx)
Get maximum humidity function.
float temphum3_get_humidity(temphum3_t *ctx)
Get humidity function.
void temphum3_set_low_hum(temphum3_t *ctx, uint8_t hum_data)
Set low humidity function.
void temphum3_generic_write(temphum3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void temphum3_set_measurement(temphum3_t *ctx, uint8_t value)
Set measurement function.
uint8_t temphum3_get_status_interrupt(temphum3_t *ctx, uint8_t mask)
Get interrupt status function.
void temphum3_set_mode(temphum3_t *ctx, uint8_t value)
Set measurement mode function.
uint8_t temphum3_get_interrupt_mask(temphum3_t *ctx, uint8_t mask)
Get interrupt mask function.
float temphum3_get_max_temp(temphum3_t *ctx)
Get maximum temperature function.
void temphum3_set_configuration(temphum3_t *ctx, uint8_t value)
Set configuration function.
void temphum3_set_offset(temphum3_t *ctx, uint8_t reg, uint8_t value)
Set offset function.
void temphum3_default_cfg(temphum3_t *ctx)
Click Default Configuration function.
err_t temphum3_init(temphum3_t *ctx, temphum3_cfg_t *cfg)
Initialization function.
void temphum3_cfg_setup(temphum3_cfg_t *cfg)
Config Object Initialization function.
void temphum3_generic_read(temphum3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
uint16_t temphum3_get_manufacturer_id(temphum3_t *ctx)
Get manufacturer's ID function.
Click configuration structure definition.
Definition temphum3.h:211
uint32_t i2c_speed
Definition temphum3.h:221
pin_name_t addr
Definition temphum3.h:217
pin_name_t scl
Definition temphum3.h:213
pin_name_t int_pin
Definition temphum3.h:218
pin_name_t sda
Definition temphum3.h:214
uint8_t i2c_address
Definition temphum3.h:222
Click ctx object definition.
Definition temphum3.h:192
digital_in_t int_pin
Definition temphum3.h:197
i2c_master_t i2c
Definition temphum3.h:200
uint8_t slave_address
Definition temphum3.h:203
digital_out_t addr
Definition temphum3.h:194