temphum10  2.0.0.0
temphum10.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 TEMPHUM10_H
36 #define TEMPHUM10_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_i2c_master.h"
50 
51 // -------------------------------------------------------------- PUBLIC MACROS
61 #define TEMPHUM10_MAP_MIKROBUS( cfg, mikrobus ) \
62  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
63  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
64  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
65 
72 #define TEMPHUM10_RETVAL uint8_t
73 
74 #define TEMPHUM10_OK 0x00
75 #define TEMPHUM10_INIT_ERROR 0xFF
76 
82 #define TEMPHUM10_REG_DEVICE_RESET 0x00
83 #define TEMPHUM10_REG_AVERAGE_MODE 0x01
84 #define TEMPHUM10_REG_ERROR_FLAG 0x03
85 #define TEMPHUM10_REG_HUMIDITY_LSB 0x04
86 #define TEMPHUM10_REG_HUMIDITY_MSB 0x05
87 #define TEMPHUM10_REG_TEMPERATURE_LSB 0x06
88 #define TEMPHUM10_REG_TEMPERATURE_MSB 0x07
89 #define TEMPHUM10_REG_CAPACITY_LSB 0x0A
90 #define TEMPHUM10_REG_CAPACITY_MSB 0x0B
91 #define TEMPHUM10_REG_CAPACITY_CTRL 0x2C
92 
98 #define TEMPHUM10_MODE_SLEEP 0x00
99 #define TEMPHUM10_MODE_STANDBY 0x01
100 
106 #define TEMPHUM10_RST_NORMAL_OPERATION 0x00
107 #define TEMPHUM10_RST_ACTIVE_RESET 0x01
108 
114 #define TEMPHUM10_AM_NO_AVERAGING_PROCESS 0x00
115 #define TEMPHUM10_AM_TIMES_AVERAGE_MODE_2 0x08
116 #define TEMPHUM10_AM_TIMES_AVERAGE_MODE_4 0x10
117 #define TEMPHUM10_AM_TIMES_AVERAGE_MODE_8 0x20
118 #define TEMPHUM10_AM_TEMP_AVERAGE_MODE_TIMES_8 0x00
119 #define TEMPHUM10_AM_TEMP_AVERAGE_MODE_TIMES_16 0x04
120 #define TEMPHUM10_AM_MANUAL_MODE_DETECTION_OP_STOP 0x00
121 #define TEMPHUM10_AM_MANUAL_MODE_DETECTION_OP_START 0x01
122 
128 #define TEMPHUM10_ERR_NO_ERROR 0x00
129 #define TEMPHUM10_ERR_ERROR_FLAG_RESET 0x01
130 
136 #define TEMPHUM10_CAP_OUTSIDE_CAPACITY_CUTTING 0x00
137 #define TEMPHUM10_CAP_OUTSIDE_CAPACITY_CONNECTION 0x10
138  // End group macro
141 // --------------------------------------------------------------- PUBLIC TYPES
150 typedef struct
151 {
152  // Output pins
153 
154  digital_out_t cs;
155 
156  // Modules
157 
158  i2c_master_t i2c;
159 
160  // ctx variable
161 
162  uint8_t slave_address;
163 
164 } temphum10_t;
165 
169 typedef struct
170 {
171  // Communication gpio pins
172 
173  pin_name_t scl;
174  pin_name_t sda;
175 
176  // Additional gpio pins
177 
178  pin_name_t cs;
179 
180  // static variable
181 
182  uint32_t i2c_speed;
183  uint8_t i2c_address;
184 
186  // End types group
188 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
189 
195 #ifdef __cplusplus
196 extern "C"{
197 #endif
198 
208 
218 
229 void temphum10_generic_write ( temphum10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
230 
241 void temphum10_generic_read ( temphum10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
242 
251 
260 
267 void temphum10_set_device_mode ( temphum10_t *ctx, uint8_t mode );
268 
275 void temphum10_repeat_measurement ( temphum10_t *ctx, uint8_t average );
276 
277 #ifdef __cplusplus
278 }
279 #endif
280 #endif // _TEMPHUM10_H_
281  // End public_function group
284 
285 // ------------------------------------------------------------------------- END
temphum10_t::i2c
i2c_master_t i2c
Definition: temphum10.h:158
temphum10_t::slave_address
uint8_t slave_address
Definition: temphum10.h:162
temphum10_t::cs
digital_out_t cs
Definition: temphum10.h:154
temphum10_get_temperature
float temphum10_get_temperature(temphum10_t *ctx)
Functions for read Temperature data.
temphum10_cfg_t
Click configuration structure definition.
Definition: temphum10.h:170
temphum10_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum10.h:183
temphum10_repeat_measurement
void temphum10_repeat_measurement(temphum10_t *ctx, uint8_t average)
Functions for repeat measurement.
temphum10_init
TEMPHUM10_RETVAL temphum10_init(temphum10_t *ctx, temphum10_cfg_t *cfg)
Initialization function.
temphum10_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum10.h:182
temphum10_cfg_t::scl
pin_name_t scl
Definition: temphum10.h:173
temphum10_generic_write
void temphum10_generic_write(temphum10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
temphum10_t
Click ctx object definition.
Definition: temphum10.h:151
temphum10_generic_read
void temphum10_generic_read(temphum10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
temphum10_get_humidity
float temphum10_get_humidity(temphum10_t *ctx)
Functions for read Relative Huminidy data.
temphum10_cfg_t::sda
pin_name_t sda
Definition: temphum10.h:174
temphum10_set_device_mode
void temphum10_set_device_mode(temphum10_t *ctx, uint8_t mode)
Functions for sets Device mode.
temphum10_cfg_setup
void temphum10_cfg_setup(temphum10_cfg_t *cfg)
Config Object Initialization function.
TEMPHUM10_RETVAL
#define TEMPHUM10_RETVAL
Definition: temphum10.h:72
temphum10_cfg_t::cs
pin_name_t cs
Definition: temphum10.h:178