thermo28  2.1.0.0
thermo28.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 THERMO28_H
29 #define THERMO28_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
72 #define THERMO28_REG_TVAL 0x00
73 #define THERMO28_REG_CONFIG 0x01
74 #define THERMO28_REG_TLOW 0x02
75 #define THERMO28_REG_THIGH 0x03
76  // thermo28_reg
78 
93 #define THERMO28_CFG_DEFAULT_CONFIG 0x40A0
94 #define THERMO28_CFG_SINGLE_SHOT 0x8000
95 #define THERMO28_CONV_RATE_BIT_MASK 0x00C0
96 #define THERMO28_STATE_BIT_MASK 0x0100
97 #define THERMO28_CONSEC_FAULTS_BIT_MASK 0x3000
98 #define THERMO28_ALERT_BIT_MASK 0x0200
99 #define THERMO28_SINGLE_SHOT_BIT_MASK 0x8000
100 
106 #define THERMO28_DEVICE_ADDRESS_VSS 0x48
107 #define THERMO28_DEVICE_ADDRESS_VDD 0x49
108 #define THERMO28_DEVICE_ADDRESS_SDA 0x4A
109 #define THERMO28_DEVICE_ADDRESS_SCL 0x4B
110  // thermo28_set
112 
127 #define THERMO28_MAP_MIKROBUS( cfg, mikrobus ) \
128  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
129  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
130  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
131  // thermo28_map // thermo28
134 
139 typedef enum
140 {
142  THERMO28_ERROR = -1
143 
145 
150 typedef enum
151 {
155  THERMO28_CONV_RATE8 = 0x00C0
156 
158 
163 typedef enum
164 {
166  THERMO28_STATE_ACTIVE = 0x0000
167 
169 
174 typedef enum
175 {
178 
180 
181 
186 typedef enum
187 {
190 
192 
197 typedef enum
198 {
202  THERMO28_CONSEC_FAULTS4 = 0x3000
203 
205 
210 typedef enum
211 {
214 
216 
221 typedef struct
222 {
223  // Input pins
224  digital_in_t int_pin;
226  // Modules
227  i2c_master_t i2c;
229  // I2C slave address
230  uint8_t slave_address;
232 } thermo28_t;
233 
238 typedef struct
239 {
240  pin_name_t scl;
241  pin_name_t sda;
243  pin_name_t int_pin;
245  uint32_t i2c_speed;
246  uint8_t i2c_address;
249 
254 typedef struct
255 {
262 
264 
281 
296 
310 
325 err_t thermo28_generic_write ( thermo28_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
326 
341 err_t thermo28_generic_read ( thermo28_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
342 
354 err_t thermo28_get_temperature ( thermo28_t *ctx, float *temperature );
355 
368 err_t thermo28_set_alert_limits ( thermo28_t *ctx, float alert_min, float alert_max );
369 
383 
396 
409 
422 
434 
435 #ifdef __cplusplus
436 }
437 #endif
438 #endif // THERMO28_H
439  // thermo28
441 
442 // ------------------------------------------------------------------------ END
THERMO28_CONV_RATE4
@ THERMO28_CONV_RATE4
Definition: thermo28.h:154
thermo28_get_int_pin
uint8_t thermo28_get_int_pin(thermo28_t *ctx)
Thermo 28 set alert status function.
THERMO28_CONSEC_FAULTS1
@ THERMO28_CONSEC_FAULTS1
Definition: thermo28.h:199
THERMO28_STATE_ACTIVE
@ THERMO28_STATE_ACTIVE
Definition: thermo28.h:166
THERMO28_ALERT_COMPARATOR
@ THERMO28_ALERT_COMPARATOR
Definition: thermo28.h:177
thermo28_generic_read
err_t thermo28_generic_read(thermo28_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Thermo 28 I2C reading function.
thermo28_get_temperature
err_t thermo28_get_temperature(thermo28_t *ctx, float *temperature)
Thermo 28 get temperature function.
thermo28_config_t::alert_mode
thermo28_alert_mode_t alert_mode
Definition: thermo28.h:258
thermo28_set_continuous_conversion
err_t thermo28_set_continuous_conversion(thermo28_t *ctx)
Thermo 28 set continuous conversion function.
thermo28_device_mode_t
thermo28_device_mode_t
Thermo 28 Click sleep mode value data.
Definition: thermo28.h:164
THERMO28_ALERT_ACTIVE_LOW
@ THERMO28_ALERT_ACTIVE_LOW
Definition: thermo28.h:188
thermo28_default_cfg
err_t thermo28_default_cfg(thermo28_t *ctx)
Thermo 28 default configuration function.
THERMO28_CONSEC_FAULTS3
@ THERMO28_CONSEC_FAULTS3
Definition: thermo28.h:201
THERMO28_CONV_RATE1
@ THERMO28_CONV_RATE1
Definition: thermo28.h:153
thermo28_return_value_t
thermo28_return_value_t
Thermo 28 Click return value data.
Definition: thermo28.h:140
THERMO28_CONV_RATE025
@ THERMO28_CONV_RATE025
Definition: thermo28.h:152
thermo28_config_t::consecutive_faults
thermo28_consec_faults_t consecutive_faults
Definition: thermo28.h:260
thermo28_t::i2c
i2c_master_t i2c
Definition: thermo28.h:227
THERMO28_ALERT_INTERRUPT
@ THERMO28_ALERT_INTERRUPT
Definition: thermo28.h:176
THERMO28_ALERT_ACTIVE_HIGH
@ THERMO28_ALERT_ACTIVE_HIGH
Definition: thermo28.h:189
THERMO28_CONV_RATE8
@ THERMO28_CONV_RATE8
Definition: thermo28.h:155
thermo28_cfg_setup
void thermo28_cfg_setup(thermo28_cfg_t *cfg)
Thermo 28 configuration object setup function.
thermo28_t::slave_address
uint8_t slave_address
Definition: thermo28.h:230
thermo28_cfg_t::i2c_address
uint8_t i2c_address
Definition: thermo28.h:246
thermo28_config_t::single_shot
thermo28_single_shot_t single_shot
Definition: thermo28.h:261
thermo28_config_t::conv_rate
thermo28_conv_rate_t conv_rate
Definition: thermo28.h:256
THERMO28_OK
@ THERMO28_OK
Definition: thermo28.h:141
thermo28_set_config
err_t thermo28_set_config(thermo28_t *ctx, thermo28_config_t config)
Thermo 28 set configuration function.
thermo28_cfg_t
Thermo 28 Click configuration object.
Definition: thermo28.h:239
thermo28_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: thermo28.h:245
thermo28_set_trigger_single_shot
err_t thermo28_set_trigger_single_shot(thermo28_t *ctx)
Thermo 28 set trigger single-shot function.
THERMO28_CONSEC_FAULTS4
@ THERMO28_CONSEC_FAULTS4
Definition: thermo28.h:202
thermo28_set_sleep_mode
err_t thermo28_set_sleep_mode(thermo28_t *ctx)
Thermo 28 set device working mode function.
thermo28_config_t::alert_polarity
thermo28_alert_polarity_t alert_polarity
Definition: thermo28.h:259
THERMO28_CONSEC_FAULTS2
@ THERMO28_CONSEC_FAULTS2
Definition: thermo28.h:200
THERMO28_SINGLE_SHOT_START_CONVERSION
@ THERMO28_SINGLE_SHOT_START_CONVERSION
Definition: thermo28.h:213
thermo28_conv_rate_t
thermo28_conv_rate_t
Thermo 28 Click conversion rate value data.
Definition: thermo28.h:151
thermo28_consec_faults_t
thermo28_consec_faults_t
Thermo 28 Click consecutive faults value data.
Definition: thermo28.h:198
thermo28_alert_polarity_t
thermo28_alert_polarity_t
Thermo 28 Click polarity of the alert output value data.
Definition: thermo28.h:187
thermo28_init
err_t thermo28_init(thermo28_t *ctx, thermo28_cfg_t *cfg)
Thermo 28 initialization function.
thermo28_cfg_t::int_pin
pin_name_t int_pin
Definition: thermo28.h:243
thermo28_generic_write
err_t thermo28_generic_write(thermo28_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Thermo 28 I2C writing function.
thermo28_set_alert_limits
err_t thermo28_set_alert_limits(thermo28_t *ctx, float alert_min, float alert_max)
Thermo 28 set alert limits function.
thermo28_config_t
Thermo 28 Click configuration object.
Definition: thermo28.h:255
thermo28_t::int_pin
digital_in_t int_pin
Definition: thermo28.h:224
THERMO28_SINGLE_SHOT_NO_CONVERSION
@ THERMO28_SINGLE_SHOT_NO_CONVERSION
Definition: thermo28.h:212
thermo28_cfg_t::scl
pin_name_t scl
Definition: thermo28.h:240
thermo28_config_t::device_mode
thermo28_device_mode_t device_mode
Definition: thermo28.h:257
THERMO28_ERROR
@ THERMO28_ERROR
Definition: thermo28.h:142
thermo28_alert_mode_t
thermo28_alert_mode_t
Thermo 28 Click interrupt mode value data.
Definition: thermo28.h:175
THERMO28_STATE_SLEEP
@ THERMO28_STATE_SLEEP
Definition: thermo28.h:165
thermo28_single_shot_t
thermo28_single_shot_t
Thermo 28 Click measurement mode value data.
Definition: thermo28.h:211
thermo28_t
Thermo 28 Click context object.
Definition: thermo28.h:222
thermo28_cfg_t::sda
pin_name_t sda
Definition: thermo28.h:241