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 
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_digital_in.h"
54 #include "drv_i2c_master.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
66 #define TEMPHUM4_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69  cfg.ad0 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70  cfg.ad1 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
71  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
72 
78 #define TEMPHUM4_RETVAL uint8_t
79 
80 #define TEMPHUM4_OK 0x00
81 #define TEMPHUM4_INIT_ERROR 0xFF
82 
88 #define TEMPHUM4_MODE_ACTIVE 0x01
89 #define TEMPHUM4_MODE_SLEEP 0x00
90 
96 #define TEMPHUM4_REG_TEMPERATURE 0x00
97 #define TEMPHUM4_REG_HUMINIDY 0x01
98 #define TEMPHUM4_REG_CONFIGURATION 0x02
99 #define TEMPHUM4_REG_MANUFACTURER_ID 0xFE
100 #define TEMPHUM4_REG_DEVICE_ID 0xFF
101 #define TEMPHUM4_REG_SERIAL_ID 0xFB
102 
108 #define TEMPHUM4_CONF_NORMAL_OPERATION ( 0x00 << 14 )
109 #define TEMPHUM4_CONF_SOFT_RESET ( 0x01 << 14 )
110 #define TEMPHUM4_CONF_HEATER_DISABLED ( 0x00 << 12 )
111 #define TEMPHUM4_CONF_HEATER_ENABLED ( 0x01 << 12 )
112 #define TEMPHUM4_CONF_MODE_TEMP_OR_HUM ( 0x00 << 11 )
113 #define TEMPHUM4_CONF_MODE_TEMP_AND_HUM ( 0x01 << 11 )
114 #define TEMPHUM4_CONF_BATTERY_VOLTAGE_2_8_V ( 0x00 << 10 )
115 #define TEMPHUM4_CONF_TEMPERATURE_14bit ( 0x00 << 9 )
116 #define TEMPHUM4_CONF_TEMPERATURE_11bit ( 0x01 << 9 )
117 #define TEMPHUM4_CONF_HUMINIDY_14bit ( 0x00 << 7 )
118 #define TEMPHUM4_CONF_HUMINIDY_11bit ( 0x01 << 7 )
119 #define TEMPHUM4_CONF_HUMINIDY_9bit ( 0x02 << 7 )
120 
126 #define TEMPHUM4_MANUFACTURER_ID 0x5449
127  // End group macro
130 // --------------------------------------------------------------- PUBLIC TYPES
139 typedef struct
140 {
141  // Output pins
142 
143  digital_out_t ad0;
144  digital_out_t ad1;
145 
146  // Input pins
147 
148  digital_in_t int_pin;
149 
150  // Modules
151 
152  i2c_master_t i2c;
153 
154  // ctx variable
155 
156  uint8_t slave_address;
157 
158 } temphum4_t;
159 
163 typedef struct
164 {
165  // Communication gpio pins
166 
167  pin_name_t scl;
168  pin_name_t sda;
169 
170  // Additional gpio pins
171 
172  pin_name_t ad0;
173  pin_name_t ad1;
174  pin_name_t int_pin;
175 
176  // static variable
177 
178  uint32_t i2c_speed;
179  uint8_t i2c_address;
180 
182  // End types group
184 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
185 
191 #ifdef __cplusplus
192 extern "C"{
193 #endif
194 
204 
214 
223 
234 void temphum4_generic_write ( temphum4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
235 
246 void temphum4_generic_read ( temphum4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
247 
256 void temphum4_set_mode ( temphum4_t *ctx, uint8_t value );
257 
266 
275 
284 void temphum4_configuration( temphum4_t *ctx, uint16_t conf_data);
285 
294 
303 
304 #ifdef __cplusplus
305 }
306 #endif
307 #endif // _TEMPHUM4_H_
308  // End public_function group
311 
312 // ------------------------------------------------------------------------- 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:179
temphum4_get_temperature
float temphum4_get_temperature(temphum4_t *ctx)
Get temperature function.
temphum4_cfg_t::ad0
pin_name_t ad0
Definition: temphum4.h:172
temphum4_t::i2c
i2c_master_t i2c
Definition: temphum4.h:152
temphum4_t::ad1
digital_out_t ad1
Definition: temphum4.h:144
temphum4_t::int_pin
digital_in_t int_pin
Definition: temphum4.h:148
temphum4_t
Click ctx object definition.
Definition: temphum4.h:140
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:178
temphum4_cfg_t::ad1
pin_name_t ad1
Definition: temphum4.h:173
temphum4_t::ad0
digital_out_t ad0
Definition: temphum4.h:143
temphum4_cfg_t
Click configuration structure definition.
Definition: temphum4.h:164
temphum4_cfg_t::int_pin
pin_name_t int_pin
Definition: temphum4.h:174
temphum4_cfg_t::scl
pin_name_t scl
Definition: temphum4.h:167
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:168
temphum4_get_humidity
float temphum4_get_humidity(temphum4_t *ctx)
Get humidity function.
TEMPHUM4_RETVAL
#define TEMPHUM4_RETVAL
Definition: temphum4.h:78
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:156
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.