temphum7  2.0.0.0
temphum7.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 TEMPHUM7_H
36 #define TEMPHUM7_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_i2c_master.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define TEMPHUM7_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.scl = MIKROBUS ( mikrobus, MIKROBUS_SCL ); \
53  cfg.sda = MIKROBUS ( mikrobus, MIKROBUS_SDA )
54 
60 #define TEMPHUM7_RETVAL uint8_t
61 
62 #define TEMPHUM7_OK 0x00
63 #define TEMPHUM7_INIT_ERROR 0xFF
64 
70 #define TEMPHUM7_DEVICE_ADDRESS 0x40
71 
77 #define TEMPHUM7_HOLD_MASTER_MODE 0x00
78 #define TEMPHUM7_NOHOLD_MASTER_MODE 0x01
79 #define TEMPHUM7_DATA_FROM_PREVIOUS_RH_MEASUREMENT 0x02
80 
86 #define TEMPHUM7_RESET 0xFE
87 #define TEMPHUM7_WRITE_RHT_USER_REGISTER_1 0xE6
88 #define TEMPHUM7_READ_RHT_USER_REGISTER_1 0xE7
89 #define TEMPHUM7_WRITE_HEATER_CONTROL_REGISTER 0x51
90 #define TEMPHUM7_READ_HEATER_CONTROL_REGISTER 0x11
91 
97 #define TEMPHUM7_RESOLUTION_12_BIT 0x00
98 #define TEMPHUM7_RESOLUTION_8_BIT 0x01
99 #define TEMPHUM7_RESOLUTION_10_BIT 0x80
100 #define TEMPHUM7_RESOLUTION_11_BIT 0x81
101 #define TEMPHUM7_HEATER_ENABLE 0x04
102 #define TEMPHUM7_HEATER_DISABLE 0x00
103 
109 #define TEMPHUM7_HEATER_CURRENT_3p09 0x00
110 #define TEMPHUM7_HEATER_CURRENT_9p17 0x01
111 #define TEMPHUM7_HEATER_CURRENT_15p24 0x02
112 #define TEMPHUM7_HEATER_CURRENT_21p31 0x03
113 #define TEMPHUM7_HEATER_CURRENT_27p39 0x04
114 #define TEMPHUM7_HEATER_CURRENT_33p46 0x05
115 #define TEMPHUM7_HEATER_CURRENT_39p53 0x06
116 #define TEMPHUM7_HEATER_CURRENT_45p61 0x07
117 #define TEMPHUM7_HEATER_CURRENT_51p68 0x08
118 #define TEMPHUM7_HEATER_CURRENT_57p76 0x09
119 #define TEMPHUM7_HEATER_CURRENT_63p83 0x0A
120 #define TEMPHUM7_HEATER_CURRENT_69p90 0x0B
121 #define TEMPHUM7_HEATER_CURRENT_75p98 0x0C
122 #define TEMPHUM7_HEATER_CURRENT_82p05 0x0D
123 #define TEMPHUM7_HEATER_CURRENT_88p13 0x0E
124 #define TEMPHUM7_HEATER_CURRENT_94p20 0x0F
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  hal_i2c_address_t slave_address;
146 
147 } temphum7_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  hal_i2c_speed_t i2c_speed;
162  hal_i2c_address_t i2c_address;
163 
165  // End types group
167 
168 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
169 
175 #ifdef __cplusplus
176 extern "C"{
177 #endif
178 
187 void temphum7_cfg_setup ( temphum7_cfg_t *cfg );
188 
197 
211 void temphum7_default_cfg ( temphum7_t *ctx );
212 
223 void temphum7_generic_write ( temphum7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
224 
236 void temphum7_generic_read ( temphum7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
237 
246 float temphum7_get_relative_humidity ( temphum7_t *ctx, uint8_t mode_data );
247 
256 float temphum7_get_temperature ( temphum7_t *ctx, uint8_t mode_data );
257 
266 void temphum7_get_electronic_serial_number ( temphum7_t *ctx, uint8_t *esn_buffer );
267 
276 
285 
293 void temphum7_reset ( temphum7_t *ctx );
294 
295 
296 #ifdef __cplusplus
297 }
298 #endif
299 #endif // _TEMPHUM7_H_
300  // End public_function group
303 
304 // ------------------------------------------------------------------------- END
pin_name_t scl
Definition: temphum7.h:156
i2c_master_t i2c
Definition: temphum7.h:141
void temphum7_generic_read(temphum7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void temphum7_default_cfg(temphum7_t *ctx)
Click Default Configuration function.
float temphum7_get_relative_humidity(temphum7_t *ctx, uint8_t mode_data)
Relative humidity.
void temphum7_cfg_setup(temphum7_cfg_t *cfg)
Config Object Initialization function.
hal_i2c_address_t slave_address
Definition: temphum7.h:145
hal_i2c_speed_t i2c_speed
Definition: temphum7.h:161
float temphum7_get_heater_current(temphum7_t *ctx)
Heater current.
TEMPHUM7_RETVAL temphum7_init(temphum7_t *ctx, temphum7_cfg_t *cfg)
Initialization function.
void temphum7_get_electronic_serial_number(temphum7_t *ctx, uint8_t *esn_buffer)
Electronic serial number.
float temphum7_get_temperature(temphum7_t *ctx, uint8_t mode_data)
Temerature.
Click ctx object definition.
Definition: temphum7.h:137
void temphum7_reset(temphum7_t *ctx)
Reset.
Click configuration structure definition.
Definition: temphum7.h:152
pin_name_t sda
Definition: temphum7.h:157
void temphum7_generic_write(temphum7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
hal_i2c_address_t i2c_address
Definition: temphum7.h:162
#define TEMPHUM7_RETVAL
Definition: temphum7.h:60
uint8_t temphum7_get_firmware_revision(temphum7_t *ctx)
Firmware revision.