temphum9  2.0.0.0
temphum9.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 TEMPHUM9_H
36 #define TEMPHUM9_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define TEMPHUM9_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
55 
62 #define TEMPHUM9_OK 0
63 #define TEMPHUM9_ERROR -1
64 
70 #define TEMPHUM9_DEVICE_ADDRESS 0x70
71 
78 #define TEMPHUM9_NORMAL_MODE 0x00
79 #define TEMPHUM9_LOW_POWER_MODE 0x01
80 
87 #define TEMPHUM9_SINGLE_DATA 0x03
88 #define TEMPHUM9_DUAL_DATA 0x06
89 
95 #define TEMPHUM9_SLEEP 0xB098
96 #define TEMPHUM9_WAKEUP 0x3517
97 #define TEMPHUM9_SOFT_RESET 0x805D
98 #define TEMPHUM9_GENERAL_CALL_RESET 0x0006
99 #define TEMPHUM9_READ_ID 0xEFC8
100  // End group macro
103 // --------------------------------------------------------------- PUBLIC TYPES
112 typedef struct
113 {
114  // Modules
115  i2c_master_t i2c;
116 
117  // ctx variable
118  uint8_t slave_address;
119 
120 } temphum9_t;
121 
125 typedef struct
126 {
127  // Communication gpio pins
128  pin_name_t scl;
129  pin_name_t sda;
130 
131  // static variable
132  uint32_t i2c_speed;
133  uint8_t i2c_address;
134 
136  // End types group
138 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
139 
145 #ifdef __cplusplus
146 extern "C"{
147 #endif
148 
158 
168 
179 void temphum9_read_register ( temphum9_t *ctx, uint16_t address, uint8_t num_data, uint16_t *data_out );
180 
189 void temphum9_send_command ( temphum9_t *ctx, uint16_t command );
190 
199 float temphum9_get_temperature ( temphum9_t *ctx, uint8_t data_mode );
200 
209 float temphum9_get_humidity ( temphum9_t *ctx, uint8_t data_mode );
210 
220 void temhum9_get_data ( temphum9_t *ctx, uint8_t data_mode, float *temp, float *hum );
221 
222 #ifdef __cplusplus
223 }
224 #endif
225 #endif // _TEMPHUM9_H_
226  // End public_function group
229 
230 // ------------------------------------------------------------------------- END
temhum9_get_data
void temhum9_get_data(temphum9_t *ctx, uint8_t data_mode, float *temp, float *hum)
Calculating temperature and relative humidity.
temphum9_t::slave_address
uint8_t slave_address
Definition: temphum9.h:118
temphum9_cfg_t::sda
pin_name_t sda
Definition: temphum9.h:129
temphum9_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum9.h:132
temphum9_cfg_setup
void temphum9_cfg_setup(temphum9_cfg_t *cfg)
Config Object Initialization function.
temphum9_t
Click ctx object definition.
Definition: temphum9.h:113
temphum9_get_temperature
float temphum9_get_temperature(temphum9_t *ctx, uint8_t data_mode)
Calculating temperature.
temphum9_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum9.h:133
temphum9_cfg_t::scl
pin_name_t scl
Definition: temphum9.h:128
temphum9_get_humidity
float temphum9_get_humidity(temphum9_t *ctx, uint8_t data_mode)
Calculating relative humidity.
temphum9_cfg_t
Click configuration structure definition.
Definition: temphum9.h:126
temphum9_read_register
void temphum9_read_register(temphum9_t *ctx, uint16_t address, uint8_t num_data, uint16_t *data_out)
Readinig register content.
temphum9_init
err_t temphum9_init(temphum9_t *ctx, temphum9_cfg_t *cfg)
Initialization function.
temphum9_t::i2c
i2c_master_t i2c
Definition: temphum9.h:115
temphum9_send_command
void temphum9_send_command(temphum9_t *ctx, uint16_t command)
Issuing a command.