temphum13  2.0.0.0
temphum13.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 TEMPHUM13_H
36 #define TEMPHUM13_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 TEMPHUM13_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
56 
62 #define TEMPHUM13_RETVAL uint8_t
63 
64 #define TEMPHUM13_OK 0x00
65 #define TEMPHUM13_INIT_ERROR 0xFF
66 
72 #define TEMPHUM13_DEVICE_ADDRESS 0x40
73 
79 #define TEMPHUM13_CMD_TRIG_TEMP_MEAS_HOLD 0xE3
80 #define TEMPHUM13_CMD_TRIG_HUMI_MEAS_HOLD 0xE5
81 #define TEMPHUM13_CMD_TRIG_TEMP_MEAS_NOHOLD 0xF3
82 #define TEMPHUM13_CMD_TRIG_HUMI_MEAS_NOHOLD 0xF5
83 #define TEMPHUM13_CMD_WRITE_USER_REG 0xE6
84 #define TEMPHUM13_CMD_READ_USER_REG 0xE7
85 #define TEMPHUM13_CMD_SOFT_RESET 0xFE
86 
93 #define TEMPHUM13_HEATER_ENABLE 0x01
94 #define TEMPHUM13_HEATER_DISABLE 0x00
95 
101 #define TEMPHUM13_RESOLUTION_8 0x01
102 #define TEMPHUM13_RESOLUTION_10 0x80
103 #define TEMPHUM13_RESOLUTION_11 0x81
104 #define TEMPHUM13_RESOLUTION_12 0x00
105 
111 #define TEMPHUM13_OTP_DISABLE 0x01
112 #define TEMPHUM13_OTP_ENABLE 0x00
113  // End group macro
117 // --------------------------------------------------------------- PUBLIC TYPES
126 typedef struct
127 {
128  // Modules
129 
130  i2c_master_t i2c;
131 
132  // ctx variable
133 
134  hal_i2c_address_t slave_address;
135 
136 } temphum13_t;
137 
141 typedef struct
142 {
143  // Communication gpio pins
144 
145  pin_name_t scl;
146  pin_name_t sda;
147 
148  // static variable
149 
150  hal_i2c_speed_t i2c_speed;
151  hal_i2c_address_t i2c_address;
152 
154  // End types group // End variable group
157 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
158 
164 #ifdef __cplusplus
165 extern "C"{
166 #endif
167 
177 
186 
195 void temphum13_default_cfg ( temphum13_t *ctx );
196 
207 void temphum13_generic_write ( temphum13_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
208 
220 void temphum13_generic_read ( temphum13_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
221 
232 
242 float temphum13_get_humidity ( temphum13_t *ctx );
243 
254 
263 void temphum13_set_user_register ( temphum13_t *ctx, uint8_t register_content );
264 
272 void temphum13_soft_reset ( temphum13_t *ctx );
273 
289 uint8_t temphum13_enable_heater ( temphum13_t *ctx, uint8_t enable_heater );
290 
307 uint8_t temphum13_change_resolution ( temphum13_t *ctx, uint8_t meas_res );
308 
324 uint8_t temphum13_disable_otp_reload ( temphum13_t *ctx, uint8_t disable_otp_rel );
325 
326 #ifdef __cplusplus
327 }
328 #endif
329 #endif // _TEMPHUM13_H_
330  // End public_function group
333 
334 // ------------------------------------------------------------------------- END
hal_i2c_address_t slave_address
Definition: temphum13.h:134
hal_i2c_address_t i2c_address
Definition: temphum13.h:151
pin_name_t sda
Definition: temphum13.h:146
void temphum13_soft_reset(temphum13_t *ctx)
Software reset.
void temphum13_generic_write(temphum13_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
Click ctx object definition.
Definition: temphum13.h:126
void temphum13_generic_read(temphum13_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
uint8_t temphum13_change_resolution(temphum13_t *ctx, uint8_t meas_res)
Change measurement resolution.
uint8_t temphum13_enable_heater(temphum13_t *ctx, uint8_t enable_heater)
Enable heater.
#define TEMPHUM13_RETVAL
Definition: temphum13.h:62
hal_i2c_speed_t i2c_speed
Definition: temphum13.h:150
void temphum13_default_cfg(temphum13_t *ctx)
Click Default Configuration function.
uint8_t temphum13_get_user_register(temphum13_t *ctx)
Get user register value.
void temphum13_cfg_setup(temphum13_cfg_t *cfg)
Config Object Initialization function.
float temphum13_get_humidity(temphum13_t *ctx)
Get humidity value.
TEMPHUM13_RETVAL temphum13_init(temphum13_t *ctx, temphum13_cfg_t *cfg)
Initialization function.
i2c_master_t i2c
Definition: temphum13.h:130
void temphum13_set_user_register(temphum13_t *ctx, uint8_t register_content)
Set user register.
uint8_t temphum13_disable_otp_reload(temphum13_t *ctx, uint8_t disable_otp_rel)
Disable OTP.
pin_name_t scl
Definition: temphum13.h:145
float temphum13_get_temperature(temphum13_t *ctx)
Get temperature value.
Click configuration structure definition.
Definition: temphum13.h:141