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 
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 TEMPHUM9_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
69 
76 #define TEMPHUM9_OK 0
77 #define TEMPHUM9_ERROR -1
78 
84 #define TEMPHUM9_DEVICE_ADDRESS 0x70
85 
92 #define TEMPHUM9_NORMAL_MODE 0x00
93 #define TEMPHUM9_LOW_POWER_MODE 0x01
94 
101 #define TEMPHUM9_SINGLE_DATA 0x03
102 #define TEMPHUM9_DUAL_DATA 0x06
103 
109 #define TEMPHUM9_SLEEP 0xB098
110 #define TEMPHUM9_WAKEUP 0x3517
111 #define TEMPHUM9_SOFT_RESET 0x805D
112 #define TEMPHUM9_GENERAL_CALL_RESET 0x0006
113 #define TEMPHUM9_READ_ID 0xEFC8
114  // End group macro
117 // --------------------------------------------------------------- PUBLIC TYPES
126 typedef struct
127 {
128  // Modules
129  i2c_master_t i2c;
130 
131  // ctx variable
132  uint8_t slave_address;
133 
134 } temphum9_t;
135 
139 typedef struct
140 {
141  // Communication gpio pins
142  pin_name_t scl;
143  pin_name_t sda;
144 
145  // static variable
146  uint32_t i2c_speed;
147  uint8_t i2c_address;
148 
150  // End types group
152 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
153 
159 #ifdef __cplusplus
160 extern "C"{
161 #endif
162 
172 
182 
193 void temphum9_read_register ( temphum9_t *ctx, uint16_t address, uint8_t num_data, uint16_t *data_out );
194 
203 void temphum9_send_command ( temphum9_t *ctx, uint16_t command );
204 
213 float temphum9_get_temperature ( temphum9_t *ctx, uint8_t data_mode );
214 
223 float temphum9_get_humidity ( temphum9_t *ctx, uint8_t data_mode );
224 
234 void temhum9_get_data ( temphum9_t *ctx, uint8_t data_mode, float *temp, float *hum );
235 
236 #ifdef __cplusplus
237 }
238 #endif
239 #endif // _TEMPHUM9_H_
240  // End public_function group
243 
244 // ------------------------------------------------------------------------- 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:132
temphum9_cfg_t::sda
pin_name_t sda
Definition: temphum9.h:143
temphum9_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum9.h:146
temphum9_cfg_setup
void temphum9_cfg_setup(temphum9_cfg_t *cfg)
Config Object Initialization function.
temphum9_t
Click ctx object definition.
Definition: temphum9.h:127
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:147
temphum9_cfg_t::scl
pin_name_t scl
Definition: temphum9.h:142
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:140
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:129
temphum9_send_command
void temphum9_send_command(temphum9_t *ctx, uint16_t command)
Issuing a command.