temphum13  2.0.0.0
temphum13.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 TEMPHUM13_H
36 #define TEMPHUM13_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 TEMPHUM13_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
69 
75 #define TEMPHUM13_RETVAL uint8_t
76 
77 #define TEMPHUM13_OK 0x00
78 #define TEMPHUM13_INIT_ERROR 0xFF
79 
85 #define TEMPHUM13_DEVICE_ADDRESS 0x40
86 
92 #define TEMPHUM13_CMD_TRIG_TEMP_MEAS_HOLD 0xE3
93 #define TEMPHUM13_CMD_TRIG_HUMI_MEAS_HOLD 0xE5
94 #define TEMPHUM13_CMD_TRIG_TEMP_MEAS_NOHOLD 0xF3
95 #define TEMPHUM13_CMD_TRIG_HUMI_MEAS_NOHOLD 0xF5
96 #define TEMPHUM13_CMD_WRITE_USER_REG 0xE6
97 #define TEMPHUM13_CMD_READ_USER_REG 0xE7
98 #define TEMPHUM13_CMD_SOFT_RESET 0xFE
99 
106 #define TEMPHUM13_HEATER_ENABLE 0x01
107 #define TEMPHUM13_HEATER_DISABLE 0x00
108 
114 #define TEMPHUM13_RESOLUTION_8 0x01
115 #define TEMPHUM13_RESOLUTION_10 0x80
116 #define TEMPHUM13_RESOLUTION_11 0x81
117 #define TEMPHUM13_RESOLUTION_12 0x00
118 
124 #define TEMPHUM13_OTP_DISABLE 0x01
125 #define TEMPHUM13_OTP_ENABLE 0x00
126  // End group macro
130 // --------------------------------------------------------------- PUBLIC TYPES
139 typedef struct
140 {
141  // Modules
142 
143  i2c_master_t i2c;
144 
145  // ctx variable
146 
147  uint8_t slave_address;
148 
149 } temphum13_t;
150 
154 typedef struct
155 {
156  // Communication gpio pins
157 
158  pin_name_t scl;
159  pin_name_t sda;
160 
161  // static variable
162 
163  uint32_t i2c_speed;
164  uint8_t i2c_address;
165 
167  // End types group // End variable group
170 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
171 
177 #ifdef __cplusplus
178 extern "C"{
179 #endif
180 
190 
200 
210 
221 void temphum13_generic_write ( temphum13_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
222 
233 void temphum13_generic_read ( temphum13_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
234 
245 
256 
267 
276 void temphum13_set_user_register ( temphum13_t *ctx, uint8_t register_content );
277 
286 
302 uint8_t temphum13_enable_heater ( temphum13_t *ctx, uint8_t enable_heater );
303 
320 uint8_t temphum13_change_resolution ( temphum13_t *ctx, uint8_t meas_res );
321 
337 uint8_t temphum13_disable_otp_reload ( temphum13_t *ctx, uint8_t disable_otp_rel );
338 
339 #ifdef __cplusplus
340 }
341 #endif
342 #endif // _TEMPHUM13_H_
343  // End public_function group
346 
347 // ------------------------------------------------------------------------- END
temphum13_generic_read
void temphum13_generic_read(temphum13_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
temphum13_t::slave_address
uint8_t slave_address
Definition: temphum13.h:147
temphum13_soft_reset
void temphum13_soft_reset(temphum13_t *ctx)
Software reset.
temphum13_cfg_t
Click configuration structure definition.
Definition: temphum13.h:155
temphum13_generic_write
void temphum13_generic_write(temphum13_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
TEMPHUM13_RETVAL
#define TEMPHUM13_RETVAL
Definition: temphum13.h:75
temphum13_cfg_t::scl
pin_name_t scl
Definition: temphum13.h:158
temphum13_cfg_t::sda
pin_name_t sda
Definition: temphum13.h:159
temphum13_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum13.h:163
temphum13_enable_heater
uint8_t temphum13_enable_heater(temphum13_t *ctx, uint8_t enable_heater)
Enable heater.
temphum13_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum13.h:164
temphum13_get_humidity
float temphum13_get_humidity(temphum13_t *ctx)
Get humidity value.
temphum13_get_temperature
float temphum13_get_temperature(temphum13_t *ctx)
Get temperature value.
temphum13_disable_otp_reload
uint8_t temphum13_disable_otp_reload(temphum13_t *ctx, uint8_t disable_otp_rel)
Disable OTP.
temphum13_cfg_setup
void temphum13_cfg_setup(temphum13_cfg_t *cfg)
Config Object Initialization function.
temphum13_t
Click ctx object definition.
Definition: temphum13.h:140
temphum13_init
TEMPHUM13_RETVAL temphum13_init(temphum13_t *ctx, temphum13_cfg_t *cfg)
Initialization function.
temphum13_get_user_register
uint8_t temphum13_get_user_register(temphum13_t *ctx)
Get user register value.
temphum13_t::i2c
i2c_master_t i2c
Definition: temphum13.h:143
temphum13_default_cfg
void temphum13_default_cfg(temphum13_t *ctx)
Click Default Configuration function.
temphum13_set_user_register
void temphum13_set_user_register(temphum13_t *ctx, uint8_t register_content)
Set user register.
temphum13_change_resolution
uint8_t temphum13_change_resolution(temphum13_t *ctx, uint8_t meas_res)
Change measurement resolution.