temphum6  2.0.0.0
temphum6.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 TEMPHUM6_H
36 #define TEMPHUM6_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 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define TEMPHUM6_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.scl= MIKROBUS( mikrobus, MIKROBUS_SCL ); \
65  cfg.sda= MIKROBUS( mikrobus, MIKROBUS_SDA )
66 
72 #define TEMPHUM6_RETVAL uint8_t
73 
74 #define TEMPHUM6_OK 0x00
75 #define TEMPHUM6_INIT_ERROR 0xFF
76 
82 #define TEMPHUM6_PART_ID 0x0210
83 #define TEMPHUM6_DEVICE_SLAVE_ADDRESS 0x43
84 
90 #define TEMPHUM6_REG_PART_ID 0x00
91 #define TEMPHUM6_REG_UNIQUE_IDENTIFIER 0x04
92 #define TEMPHUM6_REG_SYSTEM_CONTROL 0x10
93 #define TEMPHUM6_REG_SYSTEM_STATUS 0x11
94 #define TEMPHUM6_REG_SENS_RUN 0x21
95 #define TEMPHUM6_REG_SENS_START 0x22
96 #define TEMPHUM6_REG_SENS_STOP 0x23
97 #define TEMPHUM6_REG_SENS_STATUS 0x24
98 #define TEMPHUM6_REG_TEMPERATURE 0x30
99 #define TEMPHUM6_REG_RELATIVE_HUMIDITY 0x33
100 
106 #define TEMPHUM6_STATUS_I2C_ERROR 4
107 #define TEMPHUM6_STATUS_CRC_ERROR 3
108 #define TEMPHUM6_STATUS_INVALID 2
109 #define TEMPHUM6_STATUS_OK 1
110 
116 #define TEMPHUM6_TEMP_IN_FAHRENHEIT 2
117 #define TEMPHUM6_TEMP_IN_KELVIN 1
118 #define TEMPHUM6_TEMP_IN_CELSIUS 0
119 
125 #define TEMPHUM6_LOW_POWER_DISABLE 0x00
126 #define TEMPHUM6_LOW_POWER_ENABLE 0x01
127 
133 #define TEMPHUM6_SYSTEM_IS_IN_STANDBY_OR_BOOTING_STATE 0
134 #define TEMPHUM6_SYSTEM_IS_IN_ACTIVE_STATE 1
135 
141 #define TEMPHUM6_HUM_RUN_SINGLE_SHOT_MODE 0x00
142 #define TEMPHUM6_TEMP_RUN_SINGLE_SHOT_MODE 0x00
143 #define TEMPHUM6_HUM_RUN_CONTINUOUS_MODE 0x02
144 #define TEMPHUM6_TEMP_RUN_CONTINUOUS_MODE 0x01
145 
151 #define TEMPHUM6_HUM_START_MEASUREMENT 0x02
152 #define TEMPHUM6_TEMP_START_MEASUREMENT 0x01
153 #define TEMPHUM6_DISABLE_MEASUREMENT 0x00
154 
160 #define TEMPHUM6_HUM_STOP_CONTINUOUS_MEASUREMENT 0x02
161 #define TEMPHUM6_TEMP_STOP_CONTINUOUS_MEASUREMENT 0x01
162 #define TEMPHUM6_DISABLE_CONTINUOUS_MEASUREMENT 0x00
163  // End group macro
168 // --------------------------------------------------------------- PUBLIC TYPES
177 typedef struct
178 {
179  // Modules
180 
181  i2c_master_t i2c;
182 
183  // ctx variable
184 
185  uint8_t slave_address;
186 
187 } temphum6_t;
188 
192 typedef struct
193 {
194  // Communication gpio pins
195 
196  pin_name_t scl;
197  pin_name_t sda;
198 
199  // static variable
200 
201  uint32_t i2c_speed;
202  uint8_t i2c_address;
203 
205  // End types group
207 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
208 
214 #ifdef __cplusplus
215 extern "C"{
216 #endif
217 
227 
237 
248 void temphum6_generic_write ( temphum6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
249 
260 void temphum6_generic_read ( temphum6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
261 
270 
281 
293 void temphum6_run ( temphum6_t *ctx );
294 
305 float temphum6_read_temperature ( temphum6_t *ctx, uint8_t temp_in );
306 
317 
318 #ifdef __cplusplus
319 }
320 #endif
321 #endif // _TEMPHUM6_H_
322  // End public_function group
325 
326 // ------------------------------------------------------------------------- END
temphum6_t::slave_address
uint8_t slave_address
Definition: temphum6.h:185
temphum6_get_part_id
uint16_t temphum6_get_part_id(temphum6_t *ctx)
Functions for get device PART ID.
temphum6_t::i2c
i2c_master_t i2c
Definition: temphum6.h:181
temphum6_init
TEMPHUM6_RETVAL temphum6_init(temphum6_t *ctx, temphum6_cfg_t *cfg)
Initialization function.
temphum6_generic_write
void temphum6_generic_write(temphum6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
temphum6_run
void temphum6_run(temphum6_t *ctx)
Functions for RUN measurement.
TEMPHUM6_RETVAL
#define TEMPHUM6_RETVAL
Definition: temphum6.h:72
temphum6_read_temperature
float temphum6_read_temperature(temphum6_t *ctx, uint8_t temp_in)
Functions for read Temperature data.
temphum6_t
Click ctx object definition.
Definition: temphum6.h:178
temphum6_generic_read
void temphum6_generic_read(temphum6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
temphum6_read_relative_huminidy
float temphum6_read_relative_huminidy(temphum6_t *ctx)
Functions for read Relative Huminidy data.
temphum6_cfg_t
Click configuration structure definition.
Definition: temphum6.h:193
temphum6_cfg_t::scl
pin_name_t scl
Definition: temphum6.h:196
temphum6_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum6.h:202
temphum6_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum6.h:201
temphum6_cfg_setup
void temphum6_cfg_setup(temphum6_cfg_t *cfg)
Config Object Initialization function.
temphum6_cfg_t::sda
pin_name_t sda
Definition: temphum6.h:197
temphum6_reset
void temphum6_reset(temphum6_t *ctx)
Functions for reset device.