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 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_i2c_master.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
66 #define TEMPHUM2_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
69 
75 #define TEMPHUM2_RETVAL uint8_t
76 
77 #define TEMPHUM2_OK 0x00
78 #define TEMPHUM2_INIT_ERROR 0xFF
79 
85 #define TEMPHUM2_REG_FIRMWARE_REVISION 0x84F1
86 #define TEMPHUM2_REG_ELECTRONIC_ID_1 0xFA0F
87 #define TEMPHUM2_REG_ELECTRONIC_ID_2 0xFCC9
88 #define TEMPHUM2_REG_SOFT_RESET 0xFE
89 #define TEMPHUM2_REG_TEMPHUM_HM_NORMAL_MODE 0x7CA2
90 #define TEMPHUM2_REG_TEMPHUM_NHM_NORMAL_MODE 0x7866
91 #define TEMPHUM2_REG_TEMPHUM_HM_FAST_MODE 0x6458
92 #define TEMPHUM2_REG_TEMPHUM_NHM_FAST_MODE 0x609C
93 #define TEMPHUM2_REG_QUERY_DEVICE_RESP 0xEFC8
94 #define TEMPHUM2_REG_QUERY_DEVICE_RESP1 0x805D
95 #define TEMPHUM2_REG_WRITE_HEATER_CONTROL 0xE6
96 #define TEMPHUM2_REG_READ_HEATER_CONTROL 0xE7
97 
103 #define QUERY_DEVICE_ERROR 1
104 #define QUERY_DEVICE_OK 0
105 
111 #define TEMPHUM2_HEATER_ENABLE 0x10
112 #define TEMPHUM2_HEATER_DISABLE 0x00
113 #define TEMPHUM2_HEATER_CURRENT_6_4mA 0x00
114 #define TEMPHUM2_HEATER_CURRENT_9_7mA 0x01
115 #define TEMPHUM2_HEATER_CURRENT_13_1mA 0x02
116 #define TEMPHUM2_HEATER_CURRENT_19_6mA 0x04
117 #define TEMPHUM2_HEATER_CURRENT_32_4mA 0x08
118 #define TEMPHUM2_HEATER_CURRENT_53_5mA 0x0F
119 
125 #define TEMPHUM2_NO_HOLD_MODE 0x01
126 #define TEMPHUM2_HOLD_MODE 0x02
127 #define TEMPHUM2_NORMAL_MODE 0x01
128 #define TEMPHUM2_FAST_MODE 0x01
129  // End group macro
132 // --------------------------------------------------------------- PUBLIC TYPES
141 typedef struct
142 {
143  // Modules
144 
145  i2c_master_t i2c;
146 
147  // ctx variable
148 
149  uint8_t slave_address;
150 
151 } temphum2_t;
152 
156 typedef struct
157 {
158  // Communication gpio pins
159 
160  pin_name_t scl;
161  pin_name_t sda;
162 
163  // static variable
164 
165  uint32_t i2c_speed;
166  uint8_t i2c_address;
167 
169  // End types group
171 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
172 
178 #ifdef __cplusplus
179 extern "C"{
180 #endif
181 
191 
201 
217 
228 void temphum2_generic_write ( temphum2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
229 
240 void temphum2_generic_read ( temphum2_t *ctx, uint8_t *tx_buf, uint8_t *data_buf, uint8_t len );
241 
250 
257 void temhum2_get_eletronic_id ( temphum2_t *ctx, uint8_t *electronic_id );
258 
268 
275 void temphum2_set_mode ( uint8_t select_mode, uint8_t speed_mode );
276 
287 void temphum2_get_measurement ( temphum2_t *ctx, float *data_buffer );
288 
289 #ifdef __cplusplus
290 }
291 #endif
292 #endif // _TEMPHUM2_H_
293  // End public_function group
296 
297 // ------------------------------------------------------------------------- END
temphum2_cfg_t::scl
pin_name_t scl
Definition: temphum2.h:160
TEMPHUM2_RETVAL
#define TEMPHUM2_RETVAL
Definition: temphum2.h:75
temphum2_init
TEMPHUM2_RETVAL temphum2_init(temphum2_t *ctx, temphum2_cfg_t *cfg)
Initialization function.
temphum2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum2.h:165
temphum2_read_firmware_revision
uint8_t temphum2_read_firmware_revision(temphum2_t *ctx)
This function for reads Firmware Revision.
temphum2_cfg_t::sda
pin_name_t sda
Definition: temphum2.h:161
temphum2_get_query_device
uint8_t temphum2_get_query_device(temphum2_t *ctx)
This function for reads Query Device.
temphum2_default_cfg
void temphum2_default_cfg(temphum2_t *ctx)
Click Default Configuration function.
temphum2_cfg_setup
void temphum2_cfg_setup(temphum2_cfg_t *cfg)
Config Object Initialization function.
temphum2_t::slave_address
uint8_t slave_address
Definition: temphum2.h:149
temphum2_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum2.h:166
temphum2_set_mode
void temphum2_set_mode(uint8_t select_mode, uint8_t speed_mode)
Functions for set measurement mode.
temphum2_t::i2c
i2c_master_t i2c
Definition: temphum2.h:145
temphum2_cfg_t
Click configuration structure definition.
Definition: temphum2.h:157
temphum2_generic_write
void temphum2_generic_write(temphum2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
temphum2_get_measurement
void temphum2_get_measurement(temphum2_t *ctx, float *data_buffer)
Functions for mesurement.
temphum2_generic_read
void temphum2_generic_read(temphum2_t *ctx, uint8_t *tx_buf, uint8_t *data_buf, uint8_t len)
Generic read function.
temphum2_t
Click ctx object definition.
Definition: temphum2.h:142
temhum2_get_eletronic_id
void temhum2_get_eletronic_id(temphum2_t *ctx, uint8_t *electronic_id)
This function for reads Eletronic ID.