hdc1000  2.0.0.0
hdc1000.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 HDC1000_H
36 #define HDC1000_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 HDC1000_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69  cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
70 
76 #define HDC1000_RETVAL uint8_t
77 
78 #define HDC1000_OK 0x00
79 #define HDC1000_INIT_ERROR 0xFF
80 
85 #define HDC1000_SLAVE_ADDRESS 0x40
86 
92 #define HDC1000_REG_TEMP 0x00
93 #define HDC1000_REG_HUMI 0x01
94 #define HDC1000_REG_CONFIG 0x02
95 #define HDC1000_REG_SERID_1 0xFB
96 #define HDC1000_REG_SERID_2 0xFC
97 #define HDC1000_REG_SERID_3 0xFD
98 #define HDC1000_REG_MFID 0xFE
99 #define HDC1000_REG_DEVID 0xFF
100 
106 #define HDC1000_RST 0x80
107 #define HDC1000_HEAT_ON 0x20
108 #define HDC1000_HEAT_OFF 0x00
109 #define HDC1000_BOTH_TEMP_HUMI 0x10
110 #define HDC1000_SINGLE_MEASUR 0x00
111 #define HDC1000_TEMP_HUMI_14BIT 0x00
112 #define HDC1000_TEMP_11BIT 0x04
113 #define HDC1000_HUMI_11BIT 0x01
114 #define HDC1000_HUMI_8BIT 0x02
115  // End group macro
118 // --------------------------------------------------------------- PUBLIC TYPES
127 typedef struct
128 {
129  // Input pins
130 
131  digital_in_t rdy;
132 
133  // Modules
134 
135  i2c_master_t i2c;
136 
137  // ctx variable
138 
139  uint8_t slave_address;
140 
141 } hdc1000_t;
142 
146 typedef struct
147 {
148  // Communication gpio pins
149 
150  pin_name_t scl;
151  pin_name_t sda;
152 
153  // Additional gpio pins
154 
155  pin_name_t rdy;
156 
157  // static variable
158 
159  uint32_t i2c_speed;
160  uint8_t i2c_address;
161 
162 } hdc1000_cfg_t;
163  // End types group
165 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
166 
172 #ifdef __cplusplus
173 extern "C"{
174 #endif
175 
185 
195 
215 
226 void hdc1000_generic_write ( hdc1000_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
227 
238 void hdc1000_generic_read ( hdc1000_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
239 
251 
263 
282 
283 #ifdef __cplusplus
284 }
285 #endif
286 #endif // _HDC1000_H_
287  // End public_function group
290 
291 // ------------------------------------------------------------------------- END
hdc1000_cfg_t::i2c_address
uint8_t i2c_address
Definition: hdc1000.h:160
hdc1000_default_cfg
void hdc1000_default_cfg(hdc1000_t *ctx)
Click Default Configuration function.
hdc1000_t::slave_address
uint8_t slave_address
Definition: hdc1000.h:139
hdc1000_get_temperature_data
float hdc1000_get_temperature_data(hdc1000_t *ctx)
Get temperature value.
hdc1000_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: hdc1000.h:159
hdc1000_generic_write
void hdc1000_generic_write(hdc1000_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
hdc1000_cfg_t::rdy
pin_name_t rdy
Definition: hdc1000.h:155
hdc1000_get_interrupt
uint8_t hdc1000_get_interrupt(hdc1000_t *ctx)
Get interrupt state.
hdc1000_cfg_t::sda
pin_name_t sda
Definition: hdc1000.h:151
hdc1000_cfg_t::scl
pin_name_t scl
Definition: hdc1000.h:150
hdc1000_generic_read
void hdc1000_generic_read(hdc1000_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
hdc1000_get_humidity_data
float hdc1000_get_humidity_data(hdc1000_t *ctx)
Get humidity value.
hdc1000_cfg_setup
void hdc1000_cfg_setup(hdc1000_cfg_t *cfg)
Config Object Initialization function.
HDC1000_RETVAL
#define HDC1000_RETVAL
Definition: hdc1000.h:76
hdc1000_cfg_t
Click configuration structure definition.
Definition: hdc1000.h:147
hdc1000_t::i2c
i2c_master_t i2c
Definition: hdc1000.h:135
hdc1000_t
Click ctx object definition.
Definition: hdc1000.h:128
hdc1000_t::rdy
digital_in_t rdy
Definition: hdc1000.h:131
hdc1000_init
HDC1000_RETVAL hdc1000_init(hdc1000_t *ctx, hdc1000_cfg_t *cfg)
Initialization function.