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 "drv_digital_out.h"
39 #include "drv_i2c_master.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define TEMPHUM10_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
53  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
54  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
55 
62 #define TEMPHUM10_RETVAL uint8_t
63 
64 #define TEMPHUM10_OK 0x00
65 #define TEMPHUM10_INIT_ERROR 0xFF
66 
72 #define TEMPHUM10_REG_DEVICE_RESET 0x00
73 #define TEMPHUM10_REG_AVERAGE_MODE 0x01
74 #define TEMPHUM10_REG_ERROR_FLAG 0x03
75 #define TEMPHUM10_REG_HUMIDITY_LSB 0x04
76 #define TEMPHUM10_REG_HUMIDITY_MSB 0x05
77 #define TEMPHUM10_REG_TEMPERATURE_LSB 0x06
78 #define TEMPHUM10_REG_TEMPERATURE_MSB 0x07
79 #define TEMPHUM10_REG_CAPACITY_LSB 0x0A
80 #define TEMPHUM10_REG_CAPACITY_MSB 0x0B
81 #define TEMPHUM10_REG_CAPACITY_CTRL 0x2C
82 
88 #define TEMPHUM10_MODE_SLEEP 0x00
89 #define TEMPHUM10_MODE_STANDBY 0x01
90 
96 #define TEMPHUM10_RST_NORMAL_OPERATION 0x00
97 #define TEMPHUM10_RST_ACTIVE_RESET 0x01
98 
104 #define TEMPHUM10_AM_NO_AVERAGING_PROCESS 0x00
105 #define TEMPHUM10_AM_TIMES_AVERAGE_MODE_2 0x08
106 #define TEMPHUM10_AM_TIMES_AVERAGE_MODE_4 0x10
107 #define TEMPHUM10_AM_TIMES_AVERAGE_MODE_8 0x20
108 #define TEMPHUM10_AM_TEMP_AVERAGE_MODE_TIMES_8 0x00
109 #define TEMPHUM10_AM_TEMP_AVERAGE_MODE_TIMES_16 0x04
110 #define TEMPHUM10_AM_MANUAL_MODE_DETECTION_OP_STOP 0x00
111 #define TEMPHUM10_AM_MANUAL_MODE_DETECTION_OP_START 0x01
112 
118 #define TEMPHUM10_ERR_NO_ERROR 0x00
119 #define TEMPHUM10_ERR_ERROR_FLAG_RESET 0x01
120 
126 #define TEMPHUM10_CAP_OUTSIDE_CAPACITY_CUTTING 0x00
127 #define TEMPHUM10_CAP_OUTSIDE_CAPACITY_CONNECTION 0x10
128  // End group macro
131 // --------------------------------------------------------------- PUBLIC TYPES
140 typedef struct
141 {
142  // Output pins
143 
144  digital_out_t cs;
145 
146  // Modules
147 
148  i2c_master_t i2c;
149 
150  // ctx variable
151 
152  uint8_t slave_address;
153 
154 } temphum10_t;
155 
159 typedef struct
160 {
161  // Communication gpio pins
162 
163  pin_name_t scl;
164  pin_name_t sda;
165 
166  // Additional gpio pins
167 
168  pin_name_t cs;
169 
170  // static variable
171 
172  uint32_t i2c_speed;
173  uint8_t i2c_address;
174 
176  // End types group
178 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
179 
185 #ifdef __cplusplus
186 extern "C"{
187 #endif
188 
198 
208 
219 void temphum10_generic_write ( temphum10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
220 
231 void temphum10_generic_read ( temphum10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
232 
241 
250 
257 void temphum10_set_device_mode ( temphum10_t *ctx, uint8_t mode );
258 
265 void temphum10_repeat_measurement ( temphum10_t *ctx, uint8_t average );
266 
267 #ifdef __cplusplus
268 }
269 #endif
270 #endif // _TEMPHUM10_H_
271  // End public_function group
274 
275 // ------------------------------------------------------------------------- END
temphum10_t::i2c
i2c_master_t i2c
Definition: temphum10.h:148
temphum10_t::slave_address
uint8_t slave_address
Definition: temphum10.h:152
temphum10_t::cs
digital_out_t cs
Definition: temphum10.h:144
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:160
temphum10_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum10.h:173
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:172
temphum10_cfg_t::scl
pin_name_t scl
Definition: temphum10.h:163
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:141
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:164
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:62
temphum10_cfg_t::cs
pin_name_t cs
Definition: temphum10.h:168