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 
112 #define TEMPHUM4_MANUFACTURER_ID 0x5449
113  // End group macro
116 // --------------------------------------------------------------- PUBLIC TYPES
125 typedef struct
126 {
127  // Output pins
128 
129  digital_out_t ad0;
130  digital_out_t ad1;
131 
132  // Input pins
133 
134  digital_in_t int_pin;
135 
136  // Modules
137 
138  i2c_master_t i2c;
139 
140  // ctx variable
141 
142  uint8_t slave_address;
143 
144 } temphum4_t;
145 
149 typedef struct
150 {
151  // Communication gpio pins
152 
153  pin_name_t scl;
154  pin_name_t sda;
155 
156  // Additional gpio pins
157 
158  pin_name_t ad0;
159  pin_name_t ad1;
160  pin_name_t int_pin;
161 
162  // static variable
163 
164  uint32_t i2c_speed;
165  uint8_t i2c_address;
166 
168  // End types group
170 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
171 
177 #ifdef __cplusplus
178 extern "C"{
179 #endif
180 
189 void temphum4_cfg_setup ( temphum4_cfg_t *cfg );
190 
200 
208 void temphum4_default_cfg ( temphum4_t *ctx );
209 
220 void temphum4_generic_write ( temphum4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
221 
232 void temphum4_generic_read ( temphum4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
233 
242 void temphum4_set_mode ( temphum4_t *ctx, uint8_t value );
243 
251 uint16_t temphum4_get_manifacturer_id ( temphum4_t *ctx );
252 
260 uint16_t temphum4_get_device_id ( temphum4_t *ctx );
261 
270 void temphum4_configuration( temphum4_t *ctx, uint16_t conf_data);
271 
279 float temphum4_get_temperature ( temphum4_t *ctx );
280 
288 float temphum4_get_humidity ( temphum4_t *ctx );
289 
290 #ifdef __cplusplus
291 }
292 #endif
293 #endif // _TEMPHUM4_H_
294  // End public_function group
297 
298 // ------------------------------------------------------------------------- END
temphum4_init
TEMPHUM4_RETVAL temphum4_init(temphum4_t *ctx, temphum4_cfg_t *cfg)
Initialization function.
temphum4_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum4.h:165
temphum4_get_temperature
float temphum4_get_temperature(temphum4_t *ctx)
Get temperature function.
temphum4_cfg_t::ad0
pin_name_t ad0
Definition: temphum4.h:158
temphum4_t::i2c
i2c_master_t i2c
Definition: temphum4.h:138
temphum4_t::ad1
digital_out_t ad1
Definition: temphum4.h:130
temphum4_t::int_pin
digital_in_t int_pin
Definition: temphum4.h:134
temphum4_t
Click ctx object definition.
Definition: temphum4.h:125
temphum4_configuration
void temphum4_configuration(temphum4_t *ctx, uint16_t conf_data)
Set device configuration function.
temphum4_get_manifacturer_id
uint16_t temphum4_get_manifacturer_id(temphum4_t *ctx)
Get manufacturer's id.
temphum4_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum4.h:164
temphum4_cfg_t::ad1
pin_name_t ad1
Definition: temphum4.h:159
temphum4_t::ad0
digital_out_t ad0
Definition: temphum4.h:129
temphum4_cfg_t
Click configuration structure definition.
Definition: temphum4.h:149
temphum4_cfg_t::int_pin
pin_name_t int_pin
Definition: temphum4.h:160
temphum4_cfg_t::scl
pin_name_t scl
Definition: temphum4.h:153
temphum4_generic_read
void temphum4_generic_read(temphum4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
temphum4_cfg_setup
void temphum4_cfg_setup(temphum4_cfg_t *cfg)
Config Object Initialization function.
temphum4_cfg_t::sda
pin_name_t sda
Definition: temphum4.h:154
temphum4_get_humidity
float temphum4_get_humidity(temphum4_t *ctx)
Get humidity function.
TEMPHUM4_RETVAL
#define TEMPHUM4_RETVAL
Definition: temphum4.h:64
temphum4_default_cfg
void temphum4_default_cfg(temphum4_t *ctx)
Click Default Configuration function.
temphum4_set_mode
void temphum4_set_mode(temphum4_t *ctx, uint8_t value)
Set device mode function.
temphum4_t::slave_address
uint8_t slave_address
Definition: temphum4.h:142
temphum4_get_device_id
uint16_t temphum4_get_device_id(temphum4_t *ctx)
Get device id.
temphum4_generic_write
void temphum4_generic_write(temphum4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.