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 
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_i2c_master.h"
54 
55 // -------------------------------------------------------------- PUBLIC MACROS
65 #define TEMPHUM10_MAP_MIKROBUS( cfg, mikrobus ) \
66  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
67  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
68  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
69 
76 #define TEMPHUM10_RETVAL uint8_t
77 
78 #define TEMPHUM10_OK 0x00
79 #define TEMPHUM10_INIT_ERROR 0xFF
80 
86 #define TEMPHUM10_REG_DEVICE_RESET 0x00
87 #define TEMPHUM10_REG_AVERAGE_MODE 0x01
88 #define TEMPHUM10_REG_ERROR_FLAG 0x03
89 #define TEMPHUM10_REG_HUMIDITY_LSB 0x04
90 #define TEMPHUM10_REG_HUMIDITY_MSB 0x05
91 #define TEMPHUM10_REG_TEMPERATURE_LSB 0x06
92 #define TEMPHUM10_REG_TEMPERATURE_MSB 0x07
93 #define TEMPHUM10_REG_CAPACITY_LSB 0x0A
94 #define TEMPHUM10_REG_CAPACITY_MSB 0x0B
95 #define TEMPHUM10_REG_CAPACITY_CTRL 0x2C
96 
102 #define TEMPHUM10_MODE_SLEEP 0x00
103 #define TEMPHUM10_MODE_STANDBY 0x01
104 
110 #define TEMPHUM10_RST_NORMAL_OPERATION 0x00
111 #define TEMPHUM10_RST_ACTIVE_RESET 0x01
112 
118 #define TEMPHUM10_AM_NO_AVERAGING_PROCESS 0x00
119 #define TEMPHUM10_AM_TIMES_AVERAGE_MODE_2 0x08
120 #define TEMPHUM10_AM_TIMES_AVERAGE_MODE_4 0x10
121 #define TEMPHUM10_AM_TIMES_AVERAGE_MODE_8 0x20
122 #define TEMPHUM10_AM_TEMP_AVERAGE_MODE_TIMES_8 0x00
123 #define TEMPHUM10_AM_TEMP_AVERAGE_MODE_TIMES_16 0x04
124 #define TEMPHUM10_AM_MANUAL_MODE_DETECTION_OP_STOP 0x00
125 #define TEMPHUM10_AM_MANUAL_MODE_DETECTION_OP_START 0x01
126 
132 #define TEMPHUM10_ERR_NO_ERROR 0x00
133 #define TEMPHUM10_ERR_ERROR_FLAG_RESET 0x01
134 
140 #define TEMPHUM10_CAP_OUTSIDE_CAPACITY_CUTTING 0x00
141 #define TEMPHUM10_CAP_OUTSIDE_CAPACITY_CONNECTION 0x10
142  // End group macro
145 // --------------------------------------------------------------- PUBLIC TYPES
154 typedef struct
155 {
156  // Output pins
157 
158  digital_out_t cs;
159 
160  // Modules
161 
162  i2c_master_t i2c;
163 
164  // ctx variable
165 
166  uint8_t slave_address;
167 
168 } temphum10_t;
169 
173 typedef struct
174 {
175  // Communication gpio pins
176 
177  pin_name_t scl;
178  pin_name_t sda;
179 
180  // Additional gpio pins
181 
182  pin_name_t cs;
183 
184  // static variable
185 
186  uint32_t i2c_speed;
187  uint8_t i2c_address;
188 
190  // End types group
192 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
193 
199 #ifdef __cplusplus
200 extern "C"{
201 #endif
202 
212 
222 
233 void temphum10_generic_write ( temphum10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
234 
245 void temphum10_generic_read ( temphum10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
246 
255 
264 
271 void temphum10_set_device_mode ( temphum10_t *ctx, uint8_t mode );
272 
279 void temphum10_repeat_measurement ( temphum10_t *ctx, uint8_t average );
280 
281 #ifdef __cplusplus
282 }
283 #endif
284 #endif // _TEMPHUM10_H_
285  // End public_function group
288 
289 // ------------------------------------------------------------------------- END
temphum10_t::i2c
i2c_master_t i2c
Definition: temphum10.h:162
temphum10_t::slave_address
uint8_t slave_address
Definition: temphum10.h:166
temphum10_t::cs
digital_out_t cs
Definition: temphum10.h:158
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:174
temphum10_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum10.h:187
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:186
temphum10_cfg_t::scl
pin_name_t scl
Definition: temphum10.h:177
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:155
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:178
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:76
temphum10_cfg_t::cs
pin_name_t cs
Definition: temphum10.h:182