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 "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 // -------------------------------------------------------------- PUBLIC MACROS
62 #define TEMPHUM2_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
65 
71 #define TEMPHUM2_RETVAL uint8_t
72 
73 #define TEMPHUM2_OK 0x00
74 #define TEMPHUM2_INIT_ERROR 0xFF
75 
81 #define TEMPHUM2_REG_FIRMWARE_REVISION 0x84F1
82 #define TEMPHUM2_REG_ELECTRONIC_ID_1 0xFA0F
83 #define TEMPHUM2_REG_ELECTRONIC_ID_2 0xFCC9
84 #define TEMPHUM2_REG_SOFT_RESET 0xFE
85 #define TEMPHUM2_REG_TEMPHUM_HM_NORMAL_MODE 0x7CA2
86 #define TEMPHUM2_REG_TEMPHUM_NHM_NORMAL_MODE 0x7866
87 #define TEMPHUM2_REG_TEMPHUM_HM_FAST_MODE 0x6458
88 #define TEMPHUM2_REG_TEMPHUM_NHM_FAST_MODE 0x609C
89 #define TEMPHUM2_REG_QUERY_DEVICE_RESP 0xEFC8
90 #define TEMPHUM2_REG_QUERY_DEVICE_RESP1 0x805D
91 #define TEMPHUM2_REG_WRITE_HEATER_CONTROL 0xE6
92 #define TEMPHUM2_REG_READ_HEATER_CONTROL 0xE7
93 
99 #define QUERY_DEVICE_ERROR 1
100 #define QUERY_DEVICE_OK 0
101 
107 #define TEMPHUM2_HEATER_ENABLE 0x10
108 #define TEMPHUM2_HEATER_DISABLE 0x00
109 #define TEMPHUM2_HEATER_CURRENT_6_4mA 0x00
110 #define TEMPHUM2_HEATER_CURRENT_9_7mA 0x01
111 #define TEMPHUM2_HEATER_CURRENT_13_1mA 0x02
112 #define TEMPHUM2_HEATER_CURRENT_19_6mA 0x04
113 #define TEMPHUM2_HEATER_CURRENT_32_4mA 0x08
114 #define TEMPHUM2_HEATER_CURRENT_53_5mA 0x0F
115 
121 #define TEMPHUM2_NO_HOLD_MODE 0x01
122 #define TEMPHUM2_HOLD_MODE 0x02
123 #define TEMPHUM2_NORMAL_MODE 0x01
124 #define TEMPHUM2_FAST_MODE 0x01
125  // End group macro
128 // --------------------------------------------------------------- PUBLIC TYPES
137 typedef struct
138 {
139  // Modules
140 
141  i2c_master_t i2c;
142 
143  // ctx variable
144 
145  uint8_t slave_address;
146 
147 } temphum2_t;
148 
152 typedef struct
153 {
154  // Communication gpio pins
155 
156  pin_name_t scl;
157  pin_name_t sda;
158 
159  // static variable
160 
161  uint32_t i2c_speed;
162  uint8_t i2c_address;
163 
165  // End types group
167 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
168 
174 #ifdef __cplusplus
175 extern "C"{
176 #endif
177 
187 
197 
213 
224 void temphum2_generic_write ( temphum2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
225 
236 void temphum2_generic_read ( temphum2_t *ctx, uint8_t *tx_buf, uint8_t *data_buf, uint8_t len );
237 
246 
253 void temhum2_get_eletronic_id ( temphum2_t *ctx, uint8_t *electronic_id );
254 
264 
271 void temphum2_set_mode ( uint8_t select_mode, uint8_t speed_mode );
272 
283 void temphum2_get_measurement ( temphum2_t *ctx, float *data_buffer );
284 
285 #ifdef __cplusplus
286 }
287 #endif
288 #endif // _TEMPHUM2_H_
289  // End public_function group
292 
293 // ------------------------------------------------------------------------- END
temphum2_cfg_t::scl
pin_name_t scl
Definition: temphum2.h:156
TEMPHUM2_RETVAL
#define TEMPHUM2_RETVAL
Definition: temphum2.h:71
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:161
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:157
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:145
temphum2_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum2.h:162
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:141
temphum2_cfg_t
Click configuration structure definition.
Definition: temphum2.h:153
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:138
temhum2_get_eletronic_id
void temhum2_get_eletronic_id(temphum2_t *ctx, uint8_t *electronic_id)
This function for reads Eletronic ID.