temphum16  2.0.0.0
temphum16.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef TEMPHUM16_H
29 #define TEMPHUM16_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 #include "drv_spi_master.h"
49 
70 #define TEMPHUM16_REG_DEVICE_ID 0x0F
71 #define TEMPHUM16_REG_AVERAGE 0x10
72 #define TEMPHUM16_REG_CTRL_1 0x20
73 #define TEMPHUM16_REG_CTRL_2 0x21
74 #define TEMPHUM16_REG_CTRL_3 0x22
75 #define TEMPHUM16_REG_STATUS 0x27
76 #define TEMPHUM16_REG_H_OUT_L 0x28
77 #define TEMPHUM16_REG_H_OUT_H 0x29
78 #define TEMPHUM16_REG_T_OUT_L 0x2A
79 #define TEMPHUM16_REG_T_OUT_H 0x2B
80 #define TEMPHUM16_REG_H0_RH_X2 0x30
81 #define TEMPHUM16_REG_H1_RH_X2 0x31
82 #define TEMPHUM16_REG_T0_DEGC_X8 0x32
83 #define TEMPHUM16_REG_T1_DEGC_X8 0x33
84 #define TEMPHUM16_REG_T0_T1_DEGC_H2 0x35
85 #define TEMPHUM16_REG_H0_T0_OUT_L 0x36
86 #define TEMPHUM16_REG_H0_T0_OUT_H 0x37
87 #define TEMPHUM16_REG_H1_T0_OUT_L 0x3A
88 #define TEMPHUM16_REG_H1_T0_OUT_H 0x3B
89 #define TEMPHUM16_REG_T0_OUT_L 0x3C
90 #define TEMPHUM16_REG_T0_OUT_H 0x3D
91 #define TEMPHUM16_REG_T1_OUT_L 0x3E
92 #define TEMPHUM16_REG_T1_OUT_H 0x3F
93  // temphum16_reg
95 
110 #define TEMPHUM16_PWR_MODE_POWER_DOWN 0x00
111 #define TEMPHUM16_PWR_MODE_CONTINUOUS 0x01
112 
113 #define TEMPHUM16_BDU_CONTINUOUS_UPDATE 0x00
114 #define TEMPHUM16_BDU_NOT_UPDAT_UNTIL_READ 0x01
115 
116 #define TEMPHUM16_ODR_ONE_SHOT_MODE 0x00
117 #define TEMPHUM16_ODR_1_Hz 0x01
118 #define TEMPHUM16_ODR_7_Hz 0x02
119 #define TEMPHUM16_ODR_12_5_Hz 0x03
120 
121 #define TEMPHUM16_HEATER_DISABLE 0x00
122 #define TEMPHUM16_HEATER_ENABLE 0x01
123 
128 #define TEMPHUM16_DEVICE_ID 0xBC
129 
134 #define TEMPHUM16_DRDY 0x01
135 
141 #define TEMPHUM16_SET_DEV_ADDR 0x5F
142  // temphum16_set
144 
159 #define TEMPHUM16_MAP_MIKROBUS( cfg, mikrobus ) \
160  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
161  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
162  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
163  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
164  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
165  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
166  cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
167  // temphum16_map // temphum16
170 
175 typedef enum
176 {
181 
186 typedef err_t ( *temphum16_master_io_t )( struct temphum16_s*, uint8_t, uint8_t*, uint8_t );
192 typedef struct temphum16_s
193 {
194  digital_in_t rdy;
196  i2c_master_t i2c;
197  spi_master_t spi;
199  uint8_t slave_address;
200  pin_name_t chip_select;
207 
212 typedef struct
213 {
214  pin_name_t scl;
215  pin_name_t sda;
216  pin_name_t miso;
217  pin_name_t mosi;
218  pin_name_t sck;
219  pin_name_t cs;
220  pin_name_t rdy;
222  uint32_t i2c_speed;
223  uint8_t i2c_address;
225  uint32_t spi_speed;
226  spi_master_mode_t spi_mode;
227  spi_master_chip_select_polarity_t cs_polarity;
232 
237 typedef enum
238 {
240  TEMPHUM16_ERROR = -1
241 
243 
260 
276 
292 
307 
323 err_t temphum16_generic_write ( temphum16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
324 
340 err_t temphum16_generic_read ( temphum16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
341 
356 err_t temphum16_get_device_id ( temphum16_t *ctx, uint8_t *device_id );
357 
374 err_t temphum16_power_mode ( temphum16_t *ctx, uint8_t pwr_mode );
375 
392 err_t temphum16_bdu_mode ( temphum16_t *ctx, uint8_t bdu_mode );
393 
412 err_t temphum16_set_odr ( temphum16_t *ctx, uint8_t odr );
413 
430 err_t temphum16_heater ( temphum16_t *ctx, uint8_t heater_mode );
431 
446 
461 err_t temphum16_get_status ( temphum16_t *ctx, uint8_t *status );
462 
477 
494 err_t temphum16_get_humidity ( temphum16_t *ctx, float *humidity );
495 
512 err_t temphum16_get_temperature ( temphum16_t *ctx, float *temperature );
513 
514 #ifdef __cplusplus
515 }
516 #endif
517 #endif // TEMPHUM16_H
518  // temphum16
520 
521 // ------------------------------------------------------------------------ END
temphum16_s::i2c
i2c_master_t i2c
Definition: temphum16.h:196
temphum16_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: temphum16.h:226
temphum16_s::write_f
temphum16_master_io_t write_f
Definition: temphum16.h:203
temphum16_s::slave_address
uint8_t slave_address
Definition: temphum16.h:199
temphum16_default_cfg
err_t temphum16_default_cfg(temphum16_t *ctx)
Temp&Hum 16 default configuration function.
temphum16_cfg_t
Temp&Hum 16 Click configuration object.
Definition: temphum16.h:213
temphum16_cfg_t::rdy
pin_name_t rdy
Definition: temphum16.h:220
temphum16_cfg_t::sda
pin_name_t sda
Definition: temphum16.h:215
temphum16_get_status
err_t temphum16_get_status(temphum16_t *ctx, uint8_t *status)
Temp&Hum 16 get status function.
temphum16_generic_read
err_t temphum16_generic_read(temphum16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Temp&Hum 16 data reading function.
temphum16_s::drv_sel
temphum16_drv_t drv_sel
Definition: temphum16.h:201
temphum16_power_mode
err_t temphum16_power_mode(temphum16_t *ctx, uint8_t pwr_mode)
Temp&Hum 16 set power mode function.
temphum16_drv_t
temphum16_drv_t
Temp&Hum 16 Click driver selector.
Definition: temphum16.h:176
temphum16_get_humidity
err_t temphum16_get_humidity(temphum16_t *ctx, float *humidity)
Temp&Hum 16 get humidity function.
temphum16_get_device_id
err_t temphum16_get_device_id(temphum16_t *ctx, uint8_t *device_id)
Temp&Hum 16 get device ID function.
temphum16_cfg_t::cs
pin_name_t cs
Definition: temphum16.h:219
temphum16_cfg_t::drv_sel
temphum16_drv_t drv_sel
Definition: temphum16.h:229
temphum16_check_ready
uint8_t temphum16_check_ready(temphum16_t *ctx)
Temp&Hum 16 check ready function.
temphum16_drv_interface_selection
void temphum16_drv_interface_selection(temphum16_cfg_t *cfg, temphum16_drv_t drv_sel)
Temp&Hum 16 driver interface setup function.
temphum16_master_io_t
err_t(* temphum16_master_io_t)(struct temphum16_s *, uint8_t, uint8_t *, uint8_t)
Temp&Hum 16 Click driver interface.
Definition: temphum16.h:186
temphum16_s::spi
spi_master_t spi
Definition: temphum16.h:197
temphum16_s
Temp&Hum 16 Click context object.
Definition: temphum16.h:193
temphum16_cfg_setup
void temphum16_cfg_setup(temphum16_cfg_t *cfg)
Temp&Hum 16 configuration object setup function.
TEMPHUM16_ERROR
@ TEMPHUM16_ERROR
Definition: temphum16.h:240
temphum16_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: temphum16.h:227
temphum16_cfg_t::miso
pin_name_t miso
Definition: temphum16.h:216
TEMPHUM16_OK
@ TEMPHUM16_OK
Definition: temphum16.h:239
temphum16_t
struct temphum16_s temphum16_t
Temp&Hum 16 Click context object.
temphum16_cfg_t::mosi
pin_name_t mosi
Definition: temphum16.h:217
temphum16_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum16.h:223
temphum16_bdu_mode
err_t temphum16_bdu_mode(temphum16_t *ctx, uint8_t bdu_mode)
Temp&Hum 16 set block data update mode function.
TEMPHUM16_DRV_SEL_I2C
@ TEMPHUM16_DRV_SEL_I2C
Definition: temphum16.h:178
temphum16_s::chip_select
pin_name_t chip_select
Definition: temphum16.h:200
temphum16_enable_data_ready_interrupt
err_t temphum16_enable_data_ready_interrupt(temphum16_t *ctx)
Temp&Hum 16 enable data ready interrupt function.
temphum16_cfg_t::scl
pin_name_t scl
Definition: temphum16.h:214
temphum16_s::rdy
digital_in_t rdy
Definition: temphum16.h:194
temphum16_heater
err_t temphum16_heater(temphum16_t *ctx, uint8_t heater_mode)
Temp&Hum 16 heater function.
temphum16_return_value_t
temphum16_return_value_t
Temp&Hum 16 Click return value data.
Definition: temphum16.h:238
temphum16_set_odr
err_t temphum16_set_odr(temphum16_t *ctx, uint8_t odr)
Temp&Hum 16 set output data rate function.
temphum16_cfg_t::spi_speed
uint32_t spi_speed
Definition: temphum16.h:225
TEMPHUM16_DRV_SEL_SPI
@ TEMPHUM16_DRV_SEL_SPI
Definition: temphum16.h:177
temphum16_generic_write
err_t temphum16_generic_write(temphum16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Temp&Hum 16 data writing function.
temphum16_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum16.h:222
temphum16_s::read_f
temphum16_master_io_t read_f
Definition: temphum16.h:204
temphum16_init
err_t temphum16_init(temphum16_t *ctx, temphum16_cfg_t *cfg)
Temp&Hum 16 initialization function.
temphum16_cfg_t::sck
pin_name_t sck
Definition: temphum16.h:218
temphum16_get_temperature
err_t temphum16_get_temperature(temphum16_t *ctx, float *temperature)
Temp&Hum 16 get temperature function.