temphum8  2.0.0.0
temphum8.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef TEMPHUM8_H
36 #define TEMPHUM8_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_i2c_master.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define TEMPHUM8_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
53  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
54 
60 #define TEMPHUM8_RETVAL uint8_t
61 
62 #define TEMPHUM8_OK 0x00
63 #define TEMPHUM8_INIT_ERROR 0xFF
64 
70 #define TEMPHUM8_TEMP_MEASUREMENT_HOLD_MODE 0xE3
71 #define TEMPHUM8_HUM_MEASUREMENT_HOLD_MODE 0xE5
72 #define TEMPHUM8_TEMP_MEASUREMENT_NO_HOLD_MODE 0xF3
73 #define TEMPHUM8_HUM_MEASUREMENT_NO_HOLD_MODE 0xF5
74 #define TEMPHUM8_USER_REGISTER_WRITE 0xE6
75 #define TEMPHUM8_USER_REGISTER_READ 0xE7
76 #define TEMPHUM8_SOFT_RESET 0xFE
77 
83 #define TEMPHUM8_CFG_RESOLUTION_H12_T14 0x00
84 #define TEMPHUM8_CFG_RESOLUTION_H8_T12 0x01
85 #define TEMPHUM8_CFG_RESOLUTION_H10_T13 0x80
86 #define TEMPHUM8_CFG_RESOLUTION_H11_T11 0x81
87 #define TEMPHUM8_CFG_END_OF_BATTERY_LESS_THAN_2_25V 0x40
88 #define TEMPHUM8_CFG_END_OF_BATTERY_BIGGER_THAN_2_25V 0x00
89 #define TEMPHUM8_CFG_ENABLE_ON_CHIP_HEATER 0x00
90 #define TEMPHUM8_CFG_DISABLE_OTP_RELOAD 0x02
91 
97 #define TEMPHUM8_DEVICE_SLAVE_ADDRESS 0x40
98 
104 #define TEMPHUM8_TEMPERATURE_IN_CELSIUS 0x00
105 #define TEMPHUM8_TEMPERATURE_IN_KELVIN 0x01
106 #define TEMPHUM8_TEMPERATURE_IN_FARENHAJT 0x02
107  // End group macro
110 // --------------------------------------------------------------- PUBLIC TYPES
119 typedef struct
120 {
121  // Modules
122 
123  i2c_master_t i2c;
124 
125  // ctx variable
126 
127  hal_i2c_address_t slave_address;
129 
130 } temphum8_t;
131 
135 typedef struct
136 {
137  // Communication gpio pins
138 
139  pin_name_t scl;
140  pin_name_t sda;
141 
142  // static variable
143 
144  hal_i2c_speed_t i2c_speed;
145  hal_i2c_address_t i2c_address;
146  uint8_t measure_res;
147 
149  // End types group
151 
152 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
153 
159 #ifdef __cplusplus
160 extern "C"{
161 #endif
162 
171 void temphum8_cfg_setup ( temphum8_cfg_t *cfg );
172 
181 
195 void temphum8_default_cfg ( temphum8_t *ctx );
196 
207 void temphum8_generic_write ( temphum8_t *ctx, uint8_t reg, uint8_t *data_buffer, uint8_t len );
208 
219 void temphum8_generic_read ( temphum8_t *ctx, uint8_t reg, uint8_t *data_buffer, uint8_t len );
220 
226 void temphum8_software_reset ( temphum8_t *ctx );
227 
240 void temphum8_set_cfg_register ( temphum8_t *ctx, uint8_t cfg );
241 
250 float temphum8_get_temperature_data ( temphum8_t *ctx, uint8_t temp_format );
251 
260 
261 #ifdef __cplusplus
262 }
263 #endif
264 #endif // _TEMPHUM8_H_
265  // End public_function group
268 
269 // ------------------------------------------------------------------------- END
void temphum8_cfg_setup(temphum8_cfg_t *cfg)
Config Object Initialization function.
i2c_master_t i2c
Definition: temphum8.h:123
void temphum8_set_cfg_register(temphum8_t *ctx, uint8_t cfg)
Configuration device for measurement.
void temphum8_default_cfg(temphum8_t *ctx)
Click Default Configuration function.
uint8_t measure_res
Definition: temphum8.h:146
void temphum8_software_reset(temphum8_t *ctx)
Functions for device software reset.
float temphum8_get_humidity_data(temphum8_t *ctx)
Relative Huminidy data.
uint8_t measure_resolution
Definition: temphum8.h:128
TEMPHUM8_RETVAL temphum8_init(temphum8_t *ctx, temphum8_cfg_t *cfg)
Initialization function.
pin_name_t sda
Definition: temphum8.h:140
hal_i2c_address_t i2c_address
Definition: temphum8.h:145
hal_i2c_address_t slave_address
Definition: temphum8.h:127
pin_name_t scl
Definition: temphum8.h:139
void temphum8_generic_read(temphum8_t *ctx, uint8_t reg, uint8_t *data_buffer, uint8_t len)
Generic read function.
float temphum8_get_temperature_data(temphum8_t *ctx, uint8_t temp_format)
Temperature data.
Click ctx object definition.
Definition: temphum8.h:119
#define TEMPHUM8_RETVAL
Definition: temphum8.h:60
Click configuration structure definition.
Definition: temphum8.h:135
hal_i2c_speed_t i2c_speed
Definition: temphum8.h:144
void temphum8_generic_write(temphum8_t *ctx, uint8_t reg, uint8_t *data_buffer, uint8_t len)
Generic write function.