temphum6  2.0.0.0
temphum6.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 TEMPHUM6_H
36 #define TEMPHUM6_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define TEMPHUM6_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl= MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda= MIKROBUS( mikrobus, MIKROBUS_SDA );
56 
62 #define TEMPHUM6_RETVAL uint8_t
63 
64 #define TEMPHUM6_OK 0x00
65 #define TEMPHUM6_INIT_ERROR 0xFF
66 
72 #define TEMPHUM6_PART_ID 0x0210
73 #define TEMPHUM6_DEVICE_SLAVE_ADDRESS 0x43
74 
80 #define TEMPHUM6_REG_PART_ID 0x00
81 #define TEMPHUM6_REG_UNIQUE_IDENTIFIER 0x04
82 #define TEMPHUM6_REG_SYSTEM_CONTROL 0x10
83 #define TEMPHUM6_REG_SYSTEM_STATUS 0x11
84 #define TEMPHUM6_REG_SENS_RUN 0x21
85 #define TEMPHUM6_REG_SENS_START 0x22
86 #define TEMPHUM6_REG_SENS_STOP 0x23
87 #define TEMPHUM6_REG_SENS_STATUS 0x24
88 #define TEMPHUM6_REG_TEMPERATURE 0x30
89 #define TEMPHUM6_REG_RELATIVE_HUMIDITY 0x33
90 
96 #define TEMPHUM6_STATUS_I2C_ERROR 4
97 #define TEMPHUM6_STATUS_CRC_ERROR 3
98 #define TEMPHUM6_STATUS_INVALID 2
99 #define TEMPHUM6_STATUS_OK 1
100 
106 #define TEMPHUM6_TEMP_IN_FAHRENHEIT 2
107 #define TEMPHUM6_TEMP_IN_KELVIN 1
108 #define TEMPHUM6_TEMP_IN_CELSIUS 0
109 
115 #define TEMPHUM6_LOW_POWER_DISABLE 0x00
116 #define TEMPHUM6_LOW_POWER_ENABLE 0x01
117 
123 #define TEMPHUM6_SYSTEM_IS_IN_STANDBY_OR_BOOTING_STATE 0
124 #define TEMPHUM6_SYSTEM_IS_IN_ACTIVE_STATE 1
125 
131 #define TEMPHUM6_HUM_RUN_SINGLE_SHOT_MODE 0x00
132 #define TEMPHUM6_TEMP_RUN_SINGLE_SHOT_MODE 0x00
133 #define TEMPHUM6_HUM_RUN_CONTINUOUS_MODE 0x02
134 #define TEMPHUM6_TEMP_RUN_CONTINUOUS_MODE 0x01
135 
141 #define TEMPHUM6_HUM_START_MEASUREMENT 0x02
142 #define TEMPHUM6_TEMP_START_MEASUREMENT 0x01
143 #define TEMPHUM6_DISABLE_MEASUREMENT 0x00
144 
150 #define TEMPHUM6_HUM_STOP_CONTINUOUS_MEASUREMENT 0x02
151 #define TEMPHUM6_TEMP_STOP_CONTINUOUS_MEASUREMENT 0x01
152 #define TEMPHUM6_DISABLE_CONTINUOUS_MEASUREMENT 0x00
153 
159 #define CRC7WIDTH 7
160 #define CRC7POLY 0x89
161 #define CRC7IVEC 0x7F
162 
168 #define DATA7WIDTH 17
169 #define DATA7MASK ( ( 1UL << DATA7WIDTH ) -1 )
170 #define DATA7MSB ( 1UL << ( DATA7WIDTH -1 ) )
171  // End group macro
174 // --------------------------------------------------------------- PUBLIC TYPES
183 typedef struct
184 {
185  // Modules
186 
187  i2c_master_t i2c;
188 
189  // ctx variable
190 
191  hal_i2c_address_t slave_address;
192 
193 } temphum6_t;
194 
198 typedef struct
199 {
200  // Communication gpio pins
201 
202  pin_name_t scl;
203  pin_name_t sda;
204 
205  // static variable
206 
207  hal_i2c_speed_t i2c_speed;
208  hal_i2c_address_t i2c_address;
209 
211  // End types group
213 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
214 
220 #ifdef __cplusplus
221 extern "C"{
222 #endif
223 
232 void temphum6_cfg_setup ( temphum6_cfg_t *cfg );
233 
243 
254 void temphum6_generic_write ( temphum6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
255 
266 void temphum6_generic_read ( temphum6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
267 
275 void temphum6_reset ( temphum6_t *ctx );
276 
286 uint16_t temphum6_get_part_id ( temphum6_t *ctx );
287 
299 void temphum6_run ( temphum6_t *ctx );
300 
311 float temphum6_read_temperature ( temphum6_t *ctx, uint8_t temp_in );
312 
323 
324 #ifdef __cplusplus
325 }
326 #endif
327 #endif // _TEMPHUM6_H_
328  // End public_function group
331 
332 // ------------------------------------------------------------------------- END
hal_i2c_address_t slave_address
Definition: temphum6.h:191
hal_i2c_address_t i2c_address
Definition: temphum6.h:208
hal_i2c_speed_t i2c_speed
Definition: temphum6.h:207
void temphum6_reset(temphum6_t *ctx)
Functions for reset device.
void temphum6_cfg_setup(temphum6_cfg_t *cfg)
Config Object Initialization function.
float temphum6_read_temperature(temphum6_t *ctx, uint8_t temp_in)
Functions for read Temperature data.
Click ctx object definition.
Definition: temphum6.h:183
i2c_master_t i2c
Definition: temphum6.h:187
void temphum6_run(temphum6_t *ctx)
Functions for RUN measurement.
pin_name_t scl
Definition: temphum6.h:202
#define TEMPHUM6_RETVAL
Definition: temphum6.h:62
Click configuration structure definition.
Definition: temphum6.h:198
pin_name_t sda
Definition: temphum6.h:203
void temphum6_generic_write(temphum6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void temphum6_generic_read(temphum6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
uint16_t temphum6_get_part_id(temphum6_t *ctx)
Functions for get device PART ID.
TEMPHUM6_RETVAL temphum6_init(temphum6_t *ctx, temphum6_cfg_t *cfg)
Initialization function.
float temphum6_read_relative_huminidy(temphum6_t *ctx)
Functions for read Relative Huminidy data.