temphum5  2.0.0.0
temphum5.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef TEMPHUM5_H
36 #define TEMPHUM5_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define TEMPHUM5_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56  cfg.all = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
57  cfg.alh = MIKROBUS( mikrobus, MIKROBUS_INT );
58 
64 #define TEMPHUM5_RETVAL uint8_t
65 
66 #define TEMPHUM5_OK 0x00
67 #define TEMPHUM5_INIT_ERROR 0xFF
68 
74 #define TEMPHUM5_DEVICE_SLAVE_ADDRESS 0x27
75 
81 #define TEMPHUM5_TEMP_DATA_IN_CELSIUS 0x01
82 #define TEMPHUM5_TEMP_DATA_IN_KELVIN 0x02
83 #define TEMPHUM5_TEMP_DATA_IN_FAHRENHEIT 0x03
84 
91 #define TEMPHUM5_STATUS_NORMAL_OPERATION 0x00
92 #define TEMPHUM5_STATUS_STALE_DATA 0x01
93 #define TEMPHUM5_STATUS_COMMAND_MODE 0x02
94 
100 #define TEMPHUM5_ALARM_OUTPUT_HIGH 0x01
101 #define TEMPHUM5_ALARM_OUTPUT_LOW 0x02
102  // End group macro
105 // --------------------------------------------------------------- PUBLIC TYPES
114 typedef struct
115 {
116  // Input pins
117 
118  digital_in_t all;
119  digital_in_t alh;
120 
121  // Modules
122 
123  i2c_master_t i2c;
124 
125  // ctx variable
126 
127  hal_i2c_address_t slave_address;
128 
129  uint16_t temperature;
130  uint16_t humidity;
131 
132 } temphum5_t;
133 
137 typedef struct
138 {
139  // Communication gpio pins
140 
141  pin_name_t scl;
142  pin_name_t sda;
143 
144  // Additional gpio pins
145 
146  pin_name_t all;
147  pin_name_t alh;
148 
149  // static variable
150 
151  hal_i2c_speed_t i2c_speed;
152  hal_i2c_address_t i2c_address;
153 
154  uint16_t dev_temperature;
155  uint16_t dev_humidity;
156 
158  // End types group
160 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
161 
167 #ifdef __cplusplus
168 extern "C"{
169 #endif
170 
179 void temphum5_cfg_setup ( temphum5_cfg_t *cfg );
180 
189 
200 void temphum5_generic_write ( temphum5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
201 
213 void temphum5_generic_read ( temphum5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
214 
230 uint8_t temphum5_start_measurement ( temphum5_t *ctx );
231 
241 float temphum5_get_temperature ( temphum5_t *ctx, uint8_t temp_in );
242 
251 float temphum5_get_humidity ( temphum5_t *ctx );
252 
261 uint8_t temphum5_get_alarm ( temphum5_t *ctx, uint8_t alarm );
262 
263 
264 #ifdef __cplusplus
265 }
266 #endif
267 #endif // _TEMPHUM5_H_
268  // End public_function group
271 
272 // ------------------------------------------------------------------------- END
hal_i2c_speed_t i2c_speed
Definition: temphum5.h:151
pin_name_t all
Definition: temphum5.h:146
float temphum5_get_humidity(temphum5_t *ctx)
Functions for read Relative Huminidy data.
void temphum5_generic_write(temphum5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
i2c_master_t i2c
Definition: temphum5.h:123
pin_name_t sda
Definition: temphum5.h:142
#define TEMPHUM5_RETVAL
Definition: temphum5.h:64
hal_i2c_address_t i2c_address
Definition: temphum5.h:152
void temphum5_cfg_setup(temphum5_cfg_t *cfg)
Config Object Initialization function.
hal_i2c_address_t slave_address
Definition: temphum5.h:127
uint8_t temphum5_get_alarm(temphum5_t *ctx, uint8_t alarm)
Functions for get output Alarm.
pin_name_t alh
Definition: temphum5.h:147
uint16_t humidity
Definition: temphum5.h:130
digital_in_t all
Definition: temphum5.h:118
uint16_t temperature
Definition: temphum5.h:129
digital_in_t alh
Definition: temphum5.h:119
void temphum5_generic_read(temphum5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
Click ctx object definition.
Definition: temphum5.h:114
uint16_t dev_humidity
Definition: temphum5.h:155
uint16_t dev_temperature
Definition: temphum5.h:154
pin_name_t scl
Definition: temphum5.h:141
Click configuration structure definition.
Definition: temphum5.h:137
uint8_t temphum5_start_measurement(temphum5_t *ctx)
Functions for start measurement.
float temphum5_get_temperature(temphum5_t *ctx, uint8_t temp_in)
Functions for read Temperature data.
TEMPHUM5_RETVAL temphum5_init(temphum5_t *ctx, temphum5_cfg_t *cfg)
Initialization function.