temphum2  2.0.0.0
temphum2.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 TEMPHUM2_H
36 #define TEMPHUM2_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 TEMPHUM2_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
56 
62 #define TEMPHUM2_RETVAL uint8_t
63 
64 #define TEMPHUM2_OK 0x00
65 #define TEMPHUM2_INIT_ERROR 0xFF
66 
72 #define TEMPHUM2_REG_FIRMWARE_REVISION 0x84F1
73 #define TEMPHUM2_REG_ELECTRONIC_ID_1 0xFA0F
74 #define TEMPHUM2_REG_ELECTRONIC_ID_2 0xFCC9
75 #define TEMPHUM2_REG_SOFT_RESET 0xFE
76 #define TEMPHUM2_REG_TEMPHUM_HM_NORMAL_MODE 0x7CA2
77 #define TEMPHUM2_REG_TEMPHUM_NHM_NORMAL_MODE 0x7866
78 #define TEMPHUM2_REG_TEMPHUM_HM_FAST_MODE 0x6458
79 #define TEMPHUM2_REG_TEMPHUM_NHM_FAST_MODE 0x609C
80 #define TEMPHUM2_REG_QUERY_DEVICE_RESP 0xEFC8
81 #define TEMPHUM2_REG_QUERY_DEVICE_RESP1 0x805D
82 #define TEMPHUM2_REG_WRITE_HEATER_CONTROL 0xE6
83 #define TEMPHUM2_REG_READ_HEATER_CONTROL 0xE7
84 
90 #define QUERY_DEVICE_ERROR 1
91 #define QUERY_DEVICE_OK 0
92 
98 #define TEMPHUM2_HEATER_ENABLE 0x10
99 #define TEMPHUM2_HEATER_DISABLE 0x00
100 #define TEMPHUM2_HEATER_CURRENT_6_4mA 0x00
101 #define TEMPHUM2_HEATER_CURRENT_9_7mA 0x01
102 #define TEMPHUM2_HEATER_CURRENT_13_1mA 0x02
103 #define TEMPHUM2_HEATER_CURRENT_19_6mA 0x04
104 #define TEMPHUM2_HEATER_CURRENT_32_4mA 0x08
105 #define TEMPHUM2_HEATER_CURRENT_53_5mA 0x0F
106 
112 #define TEMPHUM2_NO_HOLD_MODE 0x01
113 #define TEMPHUM2_HOLD_MODE 0x02
114 #define TEMPHUM2_NORMAL_MODE 0x01
115 #define TEMPHUM2_FAST_MODE 0x01
116  // End group macro
119 // --------------------------------------------------------------- PUBLIC TYPES
128 typedef struct
129 {
130  // Modules
131 
132  i2c_master_t i2c;
133 
134  // ctx variable
135 
136  hal_i2c_address_t slave_address;
137 
138 } temphum2_t;
139 
143 typedef struct
144 {
145  // Communication gpio pins
146 
147  pin_name_t scl;
148  pin_name_t sda;
149 
150  // static variable
151 
152  hal_i2c_speed_t i2c_speed;
153  hal_i2c_address_t i2c_address;
154 
156  // End types group
158 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
159 
165 #ifdef __cplusplus
166 extern "C"{
167 #endif
168 
177 void temphum2_cfg_setup ( temphum2_cfg_t *cfg );
178 
187 
202 void temphum2_default_cfg ( temphum2_t *ctx );
203 
214 void temphum2_generic_write ( temphum2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
215 
227 void temphum2_generic_read ( temphum2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
228 
237 
244 void temhum2_get_eletronic_id ( temphum2_t *ctx, uint8_t *electronic_id );
245 
254 uint8_t temphum2_get_query_device ( temphum2_t *ctx );
255 
262 void temphum2_set_mode ( uint8_t select_mode, uint8_t speed_mode );
263 
274 void temphum2_get_measurement ( temphum2_t *ctx, float *data_buffer );
275 
276 #ifdef __cplusplus
277 }
278 #endif
279 #endif // _TEMPHUM2_H_
280  // End public_function group
283 
284 // ------------------------------------------------------------------------- END
void temphum2_default_cfg(temphum2_t *ctx)
Click Default Configuration function.
void temhum2_get_eletronic_id(temphum2_t *ctx, uint8_t *electronic_id)
This function for reads Eletronic ID.
pin_name_t sda
Definition: temphum2.h:148
hal_i2c_address_t i2c_address
Definition: temphum2.h:153
i2c_master_t i2c
Definition: temphum2.h:132
void temphum2_set_mode(uint8_t select_mode, uint8_t speed_mode)
Functions for set measurement mode.
hal_i2c_speed_t i2c_speed
Definition: temphum2.h:152
hal_i2c_address_t slave_address
Definition: temphum2.h:136
uint8_t temphum2_read_firmware_revision(temphum2_t *ctx)
This function for reads Firmware Revision.
void temphum2_get_measurement(temphum2_t *ctx, float *data_buffer)
Functions for mesurement.
void temphum2_generic_write(temphum2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void temphum2_cfg_setup(temphum2_cfg_t *cfg)
Config Object Initialization function.
uint8_t temphum2_get_query_device(temphum2_t *ctx)
This function for reads Query Device.
Click configuration structure definition.
Definition: temphum2.h:143
#define TEMPHUM2_RETVAL
Definition: temphum2.h:62
TEMPHUM2_RETVAL temphum2_init(temphum2_t *ctx, temphum2_cfg_t *cfg)
Initialization function.
Click ctx object definition.
Definition: temphum2.h:128
void temphum2_generic_read(temphum2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
pin_name_t scl
Definition: temphum2.h:147