temphum2  2.0.0.0
temphum2.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 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 // -------------------------------------------------------------- PUBLIC MACROS
52 #define TEMPHUM2_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
55 
61 #define TEMPHUM2_RETVAL uint8_t
62 
63 #define TEMPHUM2_OK 0x00
64 #define TEMPHUM2_INIT_ERROR 0xFF
65 
71 #define TEMPHUM2_REG_FIRMWARE_REVISION 0x84F1
72 #define TEMPHUM2_REG_ELECTRONIC_ID_1 0xFA0F
73 #define TEMPHUM2_REG_ELECTRONIC_ID_2 0xFCC9
74 #define TEMPHUM2_REG_SOFT_RESET 0xFE
75 #define TEMPHUM2_REG_TEMPHUM_HM_NORMAL_MODE 0x7CA2
76 #define TEMPHUM2_REG_TEMPHUM_NHM_NORMAL_MODE 0x7866
77 #define TEMPHUM2_REG_TEMPHUM_HM_FAST_MODE 0x6458
78 #define TEMPHUM2_REG_TEMPHUM_NHM_FAST_MODE 0x609C
79 #define TEMPHUM2_REG_QUERY_DEVICE_RESP 0xEFC8
80 #define TEMPHUM2_REG_QUERY_DEVICE_RESP1 0x805D
81 #define TEMPHUM2_REG_WRITE_HEATER_CONTROL 0xE6
82 #define TEMPHUM2_REG_READ_HEATER_CONTROL 0xE7
83 
89 #define QUERY_DEVICE_ERROR 1
90 #define QUERY_DEVICE_OK 0
91 
97 #define TEMPHUM2_HEATER_ENABLE 0x10
98 #define TEMPHUM2_HEATER_DISABLE 0x00
99 #define TEMPHUM2_HEATER_CURRENT_6_4mA 0x00
100 #define TEMPHUM2_HEATER_CURRENT_9_7mA 0x01
101 #define TEMPHUM2_HEATER_CURRENT_13_1mA 0x02
102 #define TEMPHUM2_HEATER_CURRENT_19_6mA 0x04
103 #define TEMPHUM2_HEATER_CURRENT_32_4mA 0x08
104 #define TEMPHUM2_HEATER_CURRENT_53_5mA 0x0F
105 
111 #define TEMPHUM2_NO_HOLD_MODE 0x01
112 #define TEMPHUM2_HOLD_MODE 0x02
113 #define TEMPHUM2_NORMAL_MODE 0x01
114 #define TEMPHUM2_FAST_MODE 0x01
115  // End group macro
118 // --------------------------------------------------------------- PUBLIC TYPES
127 typedef struct
128 {
129  // Modules
130 
131  i2c_master_t i2c;
132 
133  // ctx variable
134 
135  uint8_t slave_address;
136 
137 } temphum2_t;
138 
142 typedef struct
143 {
144  // Communication gpio pins
145 
146  pin_name_t scl;
147  pin_name_t sda;
148 
149  // static variable
150 
151  uint32_t i2c_speed;
152  uint8_t i2c_address;
153 
155  // End types group
157 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
158 
164 #ifdef __cplusplus
165 extern "C"{
166 #endif
167 
176 void temphum2_cfg_setup ( temphum2_cfg_t *cfg );
177 
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 
226 void temphum2_generic_read ( temphum2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
227 
236 
243 void temhum2_get_eletronic_id ( temphum2_t *ctx, uint8_t *electronic_id );
244 
253 uint8_t temphum2_get_query_device ( temphum2_t *ctx );
254 
261 void temphum2_set_mode ( uint8_t select_mode, uint8_t speed_mode );
262 
273 void temphum2_get_measurement ( temphum2_t *ctx, float *data_buffer );
274 
275 #ifdef __cplusplus
276 }
277 #endif
278 #endif // _TEMPHUM2_H_
279  // End public_function group
282 
283 // ------------------------------------------------------------------------- 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:147
i2c_master_t i2c
Definition: temphum2.h:131
void temphum2_set_mode(uint8_t select_mode, uint8_t speed_mode)
Functions for set measurement mode.
uint32_t i2c_speed
Definition: temphum2.h:151
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.
uint8_t slave_address
Definition: temphum2.h:135
uint8_t i2c_address
Definition: temphum2.h:152
Click configuration structure definition.
Definition: temphum2.h:142
#define TEMPHUM2_RETVAL
Definition: temphum2.h:61
TEMPHUM2_RETVAL temphum2_init(temphum2_t *ctx, temphum2_cfg_t *cfg)
Initialization function.
Click ctx object definition.
Definition: temphum2.h:127
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:146