temphum11  2.0.0.0
temphum11.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 TEMPHUM11_H
36 #define TEMPHUM11_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 TEMPHUM11_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
65 
71 #define TEMPHUM11_RETVAL uint8_t
72 
73 #define TEMPHUM11_OK 0x00
74 #define TEMPHUM11_INIT_ERROR 0xFF
75 
81 #define TEMPHUM11_REG_TEMPERATURE 0x00
82 #define TEMPHUM11_REG_HUMIDITY 0x01
83 #define TEMPHUM11_REG_CONFIGURATION 0x02
84 #define TEMPHUM11_REG_SERIAL_ID_0 0xFB
85 #define TEMPHUM11_REG_SERIAL_ID_1 0xFC
86 #define TEMPHUM11_REG_SERIAL_ID_2 0xFD
87 #define TEMPHUM11_REG_MANUFACTURER_ID 0xFE
88 #define TEMPHUM11_REG_DEVICE_ID 0xFF
89 
95 #define TEMPHUM11_NORMAL_OPERATION 0x0000
96 #define TEMPHUM11_SOFTWARE_RESET 0x8000
97 #define TEMPHUM11_HEATER_DISABLED 0x0000
98 #define TEMPHUM11_HEATER_ENABLED 0x2000
99 #define TEMPHUM11_TEMP_HUM_ACQUIRED 0x0000
100 #define TEMPHUM11_TEMP_FIRST 0x1000
101 #define TEMPHUM11_BAT_VOLT_BIGGER_THAN_2p8 0x0000
102 #define TEMPHUM11_BAT_VOLT_SMALLER_THAN_2p8 0x0800
103 #define TEMPHUM11_TEMP_RESOLUTION_14bit 0x0000
104 #define TEMPHUM11_TEMP_RESOLUTION_11bit 0x0400
105 #define TEMPHUM11_HUM_RESOLUTION_14bit 0x0000
106 #define TEMPHUM11_HUM_RESOLUTION_11bit 0x0100
107 #define TEMPHUM11_HUM_RESOLUTION_8bit 0x0200
108 
114 #define TEMPHUM11_DEVICE_SLAVE_ADDR 0x40
115 
121 #define TEMPHUM11_DEVICE_ID 0x1050
122 #define TEMPHUM11_MANUFACTURER_ID 0x5449
123 
129 #define TEMPHUM11_TEMP_IN_CELSIUS 0x00
130 #define TEMPHUM11_TEMP_IN_KELVIN 0x01
131 #define TEMPHUM11_TEMP_IN_FAHRENHEIT 0x02
132  // End group macro
134 // --------------------------------------------------------------- PUBLIC TYPES
143 typedef struct
144 {
145  // Modules
146 
147  i2c_master_t i2c;
148 
149  // ctx variable
150 
151  uint8_t slave_address;
152 
153 } temphum11_t;
154 
158 typedef struct
159 {
160  // Communication gpio pins
161 
162  pin_name_t scl;
163  pin_name_t sda;
164 
165  // Static variable
166 
167  uint32_t i2c_speed;
168  uint8_t i2c_address;
169 
171  // End types group
173 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
174 
180 #ifdef __cplusplus
181 extern "C"{
182 #endif
183 
193 
202 
211 
220 void temphum11_write_config ( temphum11_t *ctx, uint16_t config );
221 
232 uint16_t temphum11_read_data ( temphum11_t *ctx, uint8_t reg );
233 
244 float temphum11_get_temperature ( temphum11_t *ctx, uint8_t temp_in );
245 
256 
257 #ifdef __cplusplus
258 }
259 #endif
260 #endif // _TEMPHUM11_H_
261  // End public_function group
264 
265 // ------------------------------------------------------------------------- END
temphum11_init
TEMPHUM11_RETVAL temphum11_init(temphum11_t *ctx, temphum11_cfg_t *cfg)
Initialization function.
temphum11_cfg_t
Click configuration structure definition.
Definition: temphum11.h:159
temphum11_write_config
void temphum11_write_config(temphum11_t *ctx, uint16_t config)
Function for writing configuration device for measurement.
temphum11_default_cfg
void temphum11_default_cfg(temphum11_t *ctx)
Click Default Configuration function.
temphum11_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum11.h:167
temphum11_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum11.h:168
temphum11_t::i2c
i2c_master_t i2c
Definition: temphum11.h:147
TEMPHUM11_RETVAL
#define TEMPHUM11_RETVAL
Definition: temphum11.h:71
temphum11_t::slave_address
uint8_t slave_address
Definition: temphum11.h:151
temphum11_cfg_t::sda
pin_name_t sda
Definition: temphum11.h:163
temphum11_cfg_setup
void temphum11_cfg_setup(temphum11_cfg_t *cfg)
Config Object Initialization function.
temphum11_cfg_t::scl
pin_name_t scl
Definition: temphum11.h:162
temphum11_t
Click ctx object definition.
Definition: temphum11.h:144
temphum11_get_humidity
float temphum11_get_humidity(temphum11_t *ctx)
Functions for reading Relative Huminidy data.
temphum11_get_temperature
float temphum11_get_temperature(temphum11_t *ctx, uint8_t temp_in)
Functions for reading Temperature data.
temphum11_read_data
uint16_t temphum11_read_data(temphum11_t *ctx, uint8_t reg)
Functions for reading data from registers.