temphum8  2.0.0.0
temphum8.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 TEMPHUM8_H
36 #define TEMPHUM8_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_i2c_master.h"
50 
51 // -------------------------------------------------------------- PUBLIC MACROS
61 #define TEMPHUM8_MAP_MIKROBUS( cfg, mikrobus ) \
62  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
63  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
64 
70 #define TEMPHUM8_RETVAL uint8_t
71 
72 #define TEMPHUM8_OK 0x00
73 #define TEMPHUM8_INIT_ERROR 0xFF
74 
80 #define TEMPHUM8_TEMP_MEASUREMENT_HOLD_MODE 0xE3
81 #define TEMPHUM8_HUM_MEASUREMENT_HOLD_MODE 0xE5
82 #define TEMPHUM8_TEMP_MEASUREMENT_NO_HOLD_MODE 0xF3
83 #define TEMPHUM8_HUM_MEASUREMENT_NO_HOLD_MODE 0xF5
84 #define TEMPHUM8_USER_REGISTER_WRITE 0xE6
85 #define TEMPHUM8_USER_REGISTER_READ 0xE7
86 #define TEMPHUM8_SOFT_RESET 0xFE
87 
93 #define TEMPHUM8_CFG_RESOLUTION_H12_T14 0x00
94 #define TEMPHUM8_CFG_RESOLUTION_H8_T12 0x01
95 #define TEMPHUM8_CFG_RESOLUTION_H10_T13 0x80
96 #define TEMPHUM8_CFG_RESOLUTION_H11_T11 0x81
97 #define TEMPHUM8_CFG_END_OF_BATTERY_LESS_THAN_2_25V 0x40
98 #define TEMPHUM8_CFG_END_OF_BATTERY_BIGGER_THAN_2_25V 0x00
99 #define TEMPHUM8_CFG_ENABLE_ON_CHIP_HEATER 0x00
100 #define TEMPHUM8_CFG_DISABLE_OTP_RELOAD 0x02
101 
107 #define TEMPHUM8_DEVICE_SLAVE_ADDRESS 0x40
108 
114 #define TEMPHUM8_TEMPERATURE_IN_CELSIUS 0x00
115 #define TEMPHUM8_TEMPERATURE_IN_KELVIN 0x01
116 #define TEMPHUM8_TEMPERATURE_IN_FARENHAJT 0x02
117  // End group macro
120 // --------------------------------------------------------------- PUBLIC TYPES
129 typedef struct
130 {
131  // Modules
132 
133  i2c_master_t i2c;
134 
135  // ctx variable
136 
137  uint8_t slave_address;
139 
140 } temphum8_t;
141 
145 typedef struct
146 {
147  // Communication gpio pins
148 
149  pin_name_t scl;
150  pin_name_t sda;
151 
152  // static variable
153 
154  uint32_t i2c_speed;
155  uint8_t i2c_address;
156  uint8_t measure_res;
157 
159  // End types group
161 
162 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
163 
169 #ifdef __cplusplus
170 extern "C"{
171 #endif
172 
182 
192 
207 
218 void temphum8_generic_write ( temphum8_t *ctx, uint8_t reg, uint8_t *data_buffer, uint8_t len );
219 
230 void temphum8_generic_read ( temphum8_t *ctx, uint8_t reg, uint8_t *data_buffer, uint8_t len );
231 
238 
251 void temphum8_set_cfg_register ( temphum8_t *ctx, uint8_t cfg );
252 
261 float temphum8_get_temperature_data ( temphum8_t *ctx, uint8_t temp_format );
262 
271 
272 #ifdef __cplusplus
273 }
274 #endif
275 #endif // _TEMPHUM8_H_
276  // End public_function group
279 
280 // ------------------------------------------------------------------------- END
temphum8_generic_write
void temphum8_generic_write(temphum8_t *ctx, uint8_t reg, uint8_t *data_buffer, uint8_t len)
Generic write function.
temphum8_cfg_t::measure_res
uint8_t measure_res
Definition: temphum8.h:156
temphum8_cfg_setup
void temphum8_cfg_setup(temphum8_cfg_t *cfg)
Config Object Initialization function.
temphum8_get_humidity_data
float temphum8_get_humidity_data(temphum8_t *ctx)
Relative Huminidy data.
temphum8_t::i2c
i2c_master_t i2c
Definition: temphum8.h:133
temphum8_t
Click ctx object definition.
Definition: temphum8.h:130
temphum8_software_reset
void temphum8_software_reset(temphum8_t *ctx)
Functions for device software reset.
temphum8_cfg_t::scl
pin_name_t scl
Definition: temphum8.h:149
temphum8_generic_read
void temphum8_generic_read(temphum8_t *ctx, uint8_t reg, uint8_t *data_buffer, uint8_t len)
Generic read function.
temphum8_cfg_t::sda
pin_name_t sda
Definition: temphum8.h:150
temphum8_cfg_t
Click configuration structure definition.
Definition: temphum8.h:146
TEMPHUM8_RETVAL
#define TEMPHUM8_RETVAL
Definition: temphum8.h:70
temphum8_t::slave_address
uint8_t slave_address
Definition: temphum8.h:137
temphum8_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum8.h:154
temphum8_init
TEMPHUM8_RETVAL temphum8_init(temphum8_t *ctx, temphum8_cfg_t *cfg)
Initialization function.
temphum8_set_cfg_register
void temphum8_set_cfg_register(temphum8_t *ctx, uint8_t cfg)
Configuration device for measurement.
temphum8_t::measure_resolution
uint8_t measure_resolution
Definition: temphum8.h:138
temphum8_get_temperature_data
float temphum8_get_temperature_data(temphum8_t *ctx, uint8_t temp_format)
Temperature data.
temphum8_default_cfg
void temphum8_default_cfg(temphum8_t *ctx)
Click Default Configuration function.
temphum8_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum8.h:155