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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define TEMPHUM9_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
65 
72 #define TEMPHUM9_OK 0
73 #define TEMPHUM9_ERROR -1
74 
80 #define TEMPHUM9_DEVICE_ADDRESS 0x70
81 
88 #define TEMPHUM9_NORMAL_MODE 0x00
89 #define TEMPHUM9_LOW_POWER_MODE 0x01
90 
97 #define TEMPHUM9_SINGLE_DATA 0x03
98 #define TEMPHUM9_DUAL_DATA 0x06
99 
105 #define TEMPHUM9_SLEEP 0xB098
106 #define TEMPHUM9_WAKEUP 0x3517
107 #define TEMPHUM9_SOFT_RESET 0x805D
108 #define TEMPHUM9_GENERAL_CALL_RESET 0x0006
109 #define TEMPHUM9_READ_ID 0xEFC8
110  // End group macro
113 // --------------------------------------------------------------- PUBLIC TYPES
122 typedef struct
123 {
124  // Modules
125  i2c_master_t i2c;
126 
127  // ctx variable
128  uint8_t slave_address;
129 
130 } temphum9_t;
131 
135 typedef struct
136 {
137  // Communication gpio pins
138  pin_name_t scl;
139  pin_name_t sda;
140 
141  // static variable
142  uint32_t i2c_speed;
143  uint8_t i2c_address;
144 
146  // End types group
148 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
149 
155 #ifdef __cplusplus
156 extern "C"{
157 #endif
158 
168 
178 
189 void temphum9_read_register ( temphum9_t *ctx, uint16_t address, uint8_t num_data, uint16_t *data_out );
190 
199 void temphum9_send_command ( temphum9_t *ctx, uint16_t command );
200 
209 float temphum9_get_temperature ( temphum9_t *ctx, uint8_t data_mode );
210 
219 float temphum9_get_humidity ( temphum9_t *ctx, uint8_t data_mode );
220 
230 void temhum9_get_data ( temphum9_t *ctx, uint8_t data_mode, float *temp, float *hum );
231 
232 #ifdef __cplusplus
233 }
234 #endif
235 #endif // _TEMPHUM9_H_
236  // End public_function group
239 
240 // ------------------------------------------------------------------------- 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:128
temphum9_cfg_t::sda
pin_name_t sda
Definition: temphum9.h:139
temphum9_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum9.h:142
temphum9_cfg_setup
void temphum9_cfg_setup(temphum9_cfg_t *cfg)
Config Object Initialization function.
temphum9_t
Click ctx object definition.
Definition: temphum9.h:123
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:143
temphum9_cfg_t::scl
pin_name_t scl
Definition: temphum9.h:138
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:136
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:125
temphum9_send_command
void temphum9_send_command(temphum9_t *ctx, uint16_t command)
Issuing a command.