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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define TEMPHUM4_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.ad0 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
66  cfg.ad1 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
67  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
68 
74 #define TEMPHUM4_RETVAL uint8_t
75 
76 #define TEMPHUM4_OK 0x00
77 #define TEMPHUM4_INIT_ERROR 0xFF
78 
84 #define TEMPHUM4_MODE_ACTIVE 0x01
85 #define TEMPHUM4_MODE_SLEEP 0x00
86 
92 #define TEMPHUM4_REG_TEMPERATURE 0x00
93 #define TEMPHUM4_REG_HUMINIDY 0x01
94 #define TEMPHUM4_REG_CONFIGURATION 0x02
95 #define TEMPHUM4_REG_MANUFACTURER_ID 0xFE
96 #define TEMPHUM4_REG_DEVICE_ID 0xFF
97 #define TEMPHUM4_REG_SERIAL_ID 0xFB
98 
104 #define TEMPHUM4_CONF_NORMAL_OPERATION ( 0x00 << 14 )
105 #define TEMPHUM4_CONF_SOFT_RESET ( 0x01 << 14 )
106 #define TEMPHUM4_CONF_HEATER_DISABLED ( 0x00 << 12 )
107 #define TEMPHUM4_CONF_HEATER_ENABLED ( 0x01 << 12 )
108 #define TEMPHUM4_CONF_MODE_TEMP_OR_HUM ( 0x00 << 11 )
109 #define TEMPHUM4_CONF_MODE_TEMP_AND_HUM ( 0x01 << 11 )
110 #define TEMPHUM4_CONF_BATTERY_VOLTAGE_2_8_V ( 0x00 << 10 )
111 #define TEMPHUM4_CONF_TEMPERATURE_14bit ( 0x00 << 9 )
112 #define TEMPHUM4_CONF_TEMPERATURE_11bit ( 0x01 << 9 )
113 #define TEMPHUM4_CONF_HUMINIDY_14bit ( 0x00 << 7 )
114 #define TEMPHUM4_CONF_HUMINIDY_11bit ( 0x01 << 7 )
115 #define TEMPHUM4_CONF_HUMINIDY_9bit ( 0x02 << 7 )
116 
122 #define TEMPHUM4_MANUFACTURER_ID 0x5449
123  // End group macro
126 // --------------------------------------------------------------- PUBLIC TYPES
135 typedef struct
136 {
137  // Output pins
138 
139  digital_out_t ad0;
140  digital_out_t ad1;
141 
142  // Input pins
143 
144  digital_in_t int_pin;
145 
146  // Modules
147 
148  i2c_master_t i2c;
149 
150  // ctx variable
151 
152  uint8_t slave_address;
153 
154 } temphum4_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 ad0;
169  pin_name_t ad1;
170  pin_name_t int_pin;
171 
172  // static variable
173 
174  uint32_t i2c_speed;
175  uint8_t i2c_address;
176 
178  // End types group
180 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
181 
187 #ifdef __cplusplus
188 extern "C"{
189 #endif
190 
200 
210 
219 
230 void temphum4_generic_write ( temphum4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
231 
242 void temphum4_generic_read ( temphum4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
243 
252 void temphum4_set_mode ( temphum4_t *ctx, uint8_t value );
253 
262 
271 
280 void temphum4_configuration( temphum4_t *ctx, uint16_t conf_data);
281 
290 
299 
300 #ifdef __cplusplus
301 }
302 #endif
303 #endif // _TEMPHUM4_H_
304  // End public_function group
307 
308 // ------------------------------------------------------------------------- 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:175
temphum4_get_temperature
float temphum4_get_temperature(temphum4_t *ctx)
Get temperature function.
temphum4_cfg_t::ad0
pin_name_t ad0
Definition: temphum4.h:168
temphum4_t::i2c
i2c_master_t i2c
Definition: temphum4.h:148
temphum4_t::ad1
digital_out_t ad1
Definition: temphum4.h:140
temphum4_t::int_pin
digital_in_t int_pin
Definition: temphum4.h:144
temphum4_t
Click ctx object definition.
Definition: temphum4.h:136
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:174
temphum4_cfg_t::ad1
pin_name_t ad1
Definition: temphum4.h:169
temphum4_t::ad0
digital_out_t ad0
Definition: temphum4.h:139
temphum4_cfg_t
Click configuration structure definition.
Definition: temphum4.h:160
temphum4_cfg_t::int_pin
pin_name_t int_pin
Definition: temphum4.h:170
temphum4_cfg_t::scl
pin_name_t scl
Definition: temphum4.h:163
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:164
temphum4_get_humidity
float temphum4_get_humidity(temphum4_t *ctx)
Get humidity function.
TEMPHUM4_RETVAL
#define TEMPHUM4_RETVAL
Definition: temphum4.h:74
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:152
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.