temphum4  2.0.0.0
temphum4.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 TEMPHUM4_H
36 #define TEMPHUM4_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 TEMPHUM4_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.ad0 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
56  cfg.ad1 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
57  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
58 
64 #define TEMPHUM4_RETVAL uint8_t
65 
66 #define TEMPHUM4_OK 0x00
67 #define TEMPHUM4_INIT_ERROR 0xFF
68 
74 #define TEMPHUM4_MODE_ACTIVE 0x01
75 #define TEMPHUM4_MODE_SLEEP 0x00
76 
82 #define TEMPHUM4_REG_TEMPERATURE 0x00
83 #define TEMPHUM4_REG_HUMINIDY 0x01
84 #define TEMPHUM4_REG_CONFIGURATION 0x02
85 #define TEMPHUM4_REG_MANUFACTURER_ID 0xFE
86 #define TEMPHUM4_REG_DEVICE_ID 0xFF
87 #define TEMPHUM4_REG_SERIAL_ID 0xFB
88 
94 #define TEMPHUM4_CONF_NORMAL_OPERATION ( 0x00 << 14 )
95 #define TEMPHUM4_CONF_SOFT_RESET ( 0x01 << 14 )
96 #define TEMPHUM4_CONF_HEATER_DISABLED ( 0x00 << 12 )
97 #define TEMPHUM4_CONF_HEATER_ENABLED ( 0x01 << 12 )
98 #define TEMPHUM4_CONF_MODE_TEMP_OR_HUM ( 0x00 << 11 )
99 #define TEMPHUM4_CONF_MODE_TEMP_AND_HUM ( 0x01 << 11 )
100 #define TEMPHUM4_CONF_BATTERY_VOLTAGE_2_8_V ( 0x00 << 10 )
101 #define TEMPHUM4_CONF_TEMPERATURE_14bit ( 0x00 << 9 )
102 #define TEMPHUM4_CONF_TEMPERATURE_11bit ( 0x01 << 9 )
103 #define TEMPHUM4_CONF_HUMINIDY_14bit ( 0x00 << 7 )
104 #define TEMPHUM4_CONF_HUMINIDY_11bit ( 0x01 << 7 )
105 #define TEMPHUM4_CONF_HUMINIDY_9bit ( 0x02 << 7 )
106  // End group macro
109 // --------------------------------------------------------------- PUBLIC TYPES
118 typedef struct
119 {
120  // Output pins
121 
122  digital_out_t ad0;
123  digital_out_t ad1;
124 
125  // Input pins
126 
127  digital_in_t int_pin;
128 
129  // Modules
130 
131  i2c_master_t i2c;
132 
133  // ctx variable
134 
135  uint8_t slave_address;
136 
137 } temphum4_t;
138 
142 typedef struct
143 {
144  // Communication gpio pins
145 
146  pin_name_t scl;
147  pin_name_t sda;
148 
149  // Additional gpio pins
150 
151  pin_name_t ad0;
152  pin_name_t ad1;
153  pin_name_t int_pin;
154 
155  // static variable
156 
157  uint32_t i2c_speed;
158  uint8_t i2c_address;
159 
161  // End types group
163 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
164 
170 #ifdef __cplusplus
171 extern "C"{
172 #endif
173 
182 void temphum4_cfg_setup ( temphum4_cfg_t *cfg );
183 
193 
201 void temphum4_default_cfg ( temphum4_t *ctx );
202 
213 void temphum4_generic_write ( temphum4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
214 
225 void temphum4_generic_read ( temphum4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
226 
235 void temphum4_set_mode ( temphum4_t *ctx, uint8_t value );
236 
244 uint16_t temphum4_get_manifacturer_id ( temphum4_t *ctx );
245 
253 uint16_t temphum4_get_device_id ( temphum4_t *ctx );
254 
263 void temphum4_configuration( temphum4_t *ctx, uint16_t conf_data);
264 
272 float temphum4_get_temperature ( temphum4_t *ctx );
273 
281 float temphum4_get_humidity ( temphum4_t *ctx );
282 
283 #ifdef __cplusplus
284 }
285 #endif
286 #endif // _TEMPHUM4_H_
287  // End public_function group
290 
291 // ------------------------------------------------------------------------- END
digital_out_t ad1
Definition: temphum4.h:123
uint8_t slave_address
Definition: temphum4.h:135
float temphum4_get_temperature(temphum4_t *ctx)
Get temperature function.
digital_out_t ad0
Definition: temphum4.h:122
uint8_t i2c_address
Definition: temphum4.h:158
pin_name_t ad0
Definition: temphum4.h:151
void temphum4_default_cfg(temphum4_t *ctx)
Click Default Configuration function.
void temphum4_set_mode(temphum4_t *ctx, uint8_t value)
Set device mode function.
void temphum4_configuration(temphum4_t *ctx, uint16_t conf_data)
Set device configuration function.
void temphum4_generic_write(temphum4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
pin_name_t ad1
Definition: temphum4.h:152
Click ctx object definition.
Definition: temphum4.h:118
float temphum4_get_humidity(temphum4_t *ctx)
Get humidity function.
pin_name_t sda
Definition: temphum4.h:147
TEMPHUM4_RETVAL temphum4_init(temphum4_t *ctx, temphum4_cfg_t *cfg)
Initialization function.
void temphum4_cfg_setup(temphum4_cfg_t *cfg)
Config Object Initialization function.
uint32_t i2c_speed
Definition: temphum4.h:157
pin_name_t scl
Definition: temphum4.h:146
pin_name_t int_pin
Definition: temphum4.h:153
Click configuration structure definition.
Definition: temphum4.h:142
void temphum4_generic_read(temphum4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
i2c_master_t i2c
Definition: temphum4.h:131
#define TEMPHUM4_RETVAL
Definition: temphum4.h:64
uint16_t temphum4_get_manifacturer_id(temphum4_t *ctx)
Get manufacturer&#39;s id.
digital_in_t int_pin
Definition: temphum4.h:127
uint16_t temphum4_get_device_id(temphum4_t *ctx)
Get device id.