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_RETVAL uint8_t
63 
64 #define TEMPHUM9_OK 0x00
65 #define TEMPHUM9_INIT_ERROR 0xFF
66 
72 #define TEMPHUM9_DEVICE_ADDRESS 0x70
73 
80 #define TEMPHUM9_NORMAL_MODE 0x00
81 #define TEMPHUM9_LOW_POWER_MODE 0x01
82 
89 #define TEMPHUM9_SINGLE_DATA 0x03
90 #define TEMPHUM9_DUAL_DATA 0x06
91 
98 #define TEMPHUM9_SLEEP 0xB098
99 #define TEMPHUM9_WAKEUP 0x3517
100 #define TEMPHUM9_SOFT_RESET 0x805D
101 #define TEMPHUM9_GENERAL_CALL_RESET 0x0006
102 #define TEMPHUM9_READ_ID 0xEFC8
103  // End group macro
106 // --------------------------------------------------------------- PUBLIC TYPES
115 typedef struct
116 {
117  // Modules
118 
119  i2c_master_t i2c;
120 
121  // ctx variable
122 
123  uint8_t slave_address;
124 
125 } temphum9_t;
126 
130 typedef struct
131 {
132  // Communication gpio pins
133 
134  pin_name_t scl;
135  pin_name_t sda;
136 
137  // static variable
138 
139  uint32_t i2c_speed;
140  uint8_t i2c_address;
141 
143  // End types group
145 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
146 
152 #ifdef __cplusplus
153 extern "C"{
154 #endif
155 
164 void temphum9_cfg_setup ( temphum9_cfg_t *cfg );
165 
175 
183 void temphum9_default_cfg ( temphum9_t *ctx );
184 
195 void temphum9_generic_write ( temphum9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
196 
207 void temphum9_generic_read ( temphum9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
208 
219 void temphum9_read_register ( temphum9_t *ctx, uint16_t register_address, uint8_t n_data_, uint16_t *register_buffer );
220 
229 void temphum9_send_command ( temphum9_t *ctx, uint16_t command );
230 
239 float temphum9_get_temperature ( temphum9_t *ctx, uint8_t data_mode );
240 
249 float temphum9_get_relative_humidity ( temphum9_t *ctx, uint8_t data_mode );
250 
259 void temhum9_get_temperature_and_humidity ( temphum9_t *ctx, uint8_t data_mode , float *measurement_data );
260 
261 
262 #ifdef __cplusplus
263 }
264 #endif
265 #endif // _TEMPHUM9_H_
266  // End public_function group
269 
270 // ------------------------------------------------------------------------- END
temphum9_t::slave_address
uint8_t slave_address
Definition: temphum9.h:123
temphum9_cfg_t::sda
pin_name_t sda
Definition: temphum9.h:135
temphum9_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum9.h:139
temphum9_cfg_setup
void temphum9_cfg_setup(temphum9_cfg_t *cfg)
Config Object Initialization function.
temphum9_t
Click ctx object definition.
Definition: temphum9.h:115
temphum9_get_relative_humidity
float temphum9_get_relative_humidity(temphum9_t *ctx, uint8_t data_mode)
Calculating relative humidity.
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:140
temphum9_default_cfg
void temphum9_default_cfg(temphum9_t *ctx)
Click Default Configuration function.
temphum9_init
TEMPHUM9_RETVAL temphum9_init(temphum9_t *ctx, temphum9_cfg_t *cfg)
Initialization function.
temphum9_cfg_t::scl
pin_name_t scl
Definition: temphum9.h:134
temphum9_generic_write
void temphum9_generic_write(temphum9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
TEMPHUM9_RETVAL
#define TEMPHUM9_RETVAL
Definition: temphum9.h:62
temhum9_get_temperature_and_humidity
void temhum9_get_temperature_and_humidity(temphum9_t *ctx, uint8_t data_mode, float *measurement_data)
Calculating temperature and relative humidity.
temphum9_cfg_t
Click configuration structure definition.
Definition: temphum9.h:130
measurement_data
float measurement_data[2]
Definition: main.c:32
temphum9_t::i2c
i2c_master_t i2c
Definition: temphum9.h:119
temphum9_send_command
void temphum9_send_command(temphum9_t *ctx, uint16_t command)
Issuing a command.
temphum9_generic_read
void temphum9_generic_read(temphum9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
temphum9_read_register
void temphum9_read_register(temphum9_t *ctx, uint16_t register_address, uint8_t n_data_, uint16_t *register_buffer)
Readinig register content.