surfacetemp2  2.0.0.0
surfacetemp2.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 SURFACETEMP2_H
36 #define SURFACETEMP2_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define SURFACETEMP2_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
56  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
57 
63 #define SURFACETEMP2_RETVAL uint8_t
64 
65 #define SURFACETEMP2_OK 0x00
66 #define SURFACETEMP2_INIT_ERROR 0xFF
67 
73 #define SURFACETEMP2_I2C_DEV_ADR_0_0 0x48
74 #define SURFACETEMP2_I2C_DEV_ADR_0_1 0x49
75 #define SURFACETEMP2_I2C_DEV_ADR_1_0 0x4A
76 #define SURFACETEMP2_I2C_DEV_ADR_1_1 0x4B
77 
83 #define SURFACETEMP2_REG_TEMP_MSB 0x00
84 #define SURFACETEMP2_REG_TEMP_LSB 0x01
85 #define SURFACETEMP2_REG_STAT 0x02
86 #define SURFACETEMP2_REG_CFG 0x03
87 #define SURFACETEMP2_REG_T_HIGH_SETP_MSB 0x04
88 #define SURFACETEMP2_REG_T_HIGH_SETP_LSB 0x05
89 #define SURFACETEMP2_REG_T_LOW_SETP_MSB 0x06
90 #define SURFACETEMP2_REG_T_LOW_SETP_LSB 0x07
91 #define SURFACETEMP2_REG_T_CRIT_SETP_MSB 0x08
92 #define SURFACETEMP2_REG_T_CRIT_SETP_LSB 0x09
93 #define SURFACETEMP2_REG_T_HYST_SETP 0x0A
94 #define SURFACETEMP2_REG_ID 0x0B
95 #define SURFACETEMP2_REG_SOFT_RESET 0x2F
96 
102 #define SURFACETEMP2_STAT_T_LOW_MSK 0x10
103 #define SURFACETEMP2_STAT_T_HIGH_MSK 0x20
104 #define SURFACETEMP2_STAT_T_CRIT_MSK 0x40
105 #define SURFACETEMP2_STAT_RDY_MSK 0x80
106 
112 #define SURFACETEMP2_CFG_FLT_Q_1 0x00
113 #define SURFACETEMP2_CFG_FLT_Q_2 0x01
114 #define SURFACETEMP2_CFG_FLT_Q_3 0x02
115 #define SURFACETEMP2_CFG_FLT_Q_4 0x03
116 #define SURFACETEMP2_CFG_CT_POL_ACT_H 0x04
117 #define SURFACETEMP2_CFG_CT_POL_ACT_L 0x00
118 #define SURFACETEMP2_CFG_INT_POL_ACT_H 0x08
119 #define SURFACETEMP2_CFG_INT_POL_ACT_L 0x00
120 #define SURFACETEMP2_CFG_INT_MODE 0x00
121 #define SURFACETEMP2_CFG_CT_MODE 0x10
122 #define SURFACETEMP2_CFG_OP_MODE_CONT 0x00
123 #define SURFACETEMP2_CFG_OP_MODE_ONE_SHT 0x20
124 #define SURFACETEMP2_CFG_OP_MODE_SPS 0x40
125 #define SURFACETEMP2_CFG_OP_MODE_SHDN 0x60
126 #define SURFACETEMP2_CFG_RES_13 0x00
127 #define SURFACETEMP2_CFG_RES_16 0x80
128 
134 #define SURFACETEMP2_RES_13_BIT 0.0625
135 #define SURFACETEMP2_RES_16_BIT 0.0078125
136 
142 #define SURFACETEMP2_DEV_ID_VAL 0xCB
143 
149 #define SURFACETEMP2_DEV_OK 0x00
150 #define SURFACETEMP2_DEV_NOK 0x01
151  // End group macro
154 // --------------------------------------------------------------- PUBLIC TYPES
163 typedef struct
164 {
165  // Input pins
166 
167  digital_in_t pwm;
168  digital_in_t int_pin;
169 
170  // Modules
171 
172  i2c_master_t i2c;
173 
174  // ctx variable
175 
176  uint8_t slave_address;
177 
179 
183 typedef struct
184 {
185  // Communication gpio pins
186 
187  pin_name_t scl;
188  pin_name_t sda;
189 
190  // Additional gpio pins
191 
192  pin_name_t pwm;
193  pin_name_t int_pin;
194 
195  // static variable
196 
197  uint32_t i2c_speed;
198  uint8_t i2c_address;
199 
201  // End types group
203 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
204 
210 #ifdef __cplusplus
211 extern "C"{
212 #endif
213 
223 
232 
243 void surfacetemp2_generic_write ( surfacetemp2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
244 
256 void surfacetemp2_generic_read ( surfacetemp2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
257 
267 
281 uint8_t surfacetemp2_setup ( surfacetemp2_t *ctx, uint8_t setup );
282 
292 void surfacetemp2_set_hys_val ( surfacetemp2_t *ctx, uint8_t hys_val );
293 
305 
314 void surfacetemp2_set_high_trsh ( surfacetemp2_t *ctx, float trsh );
315 
324 void surfacetemp2_set_low_trsh ( surfacetemp2_t *ctx, float trsh );
325 
334 void surfacetemp2_set_crit_trsh ( surfacetemp2_t *ctx, float trsh );
335 
348 
361 
362 #ifdef __cplusplus
363 }
364 #endif
365 #endif // _SURFACETEMP2_H_
366  // End public_function group
369 
370 // ------------------------------------------------------------------------- END
surfacetemp2_get_ct_pin
uint8_t surfacetemp2_get_ct_pin(surfacetemp2_t *ctx)
Get CT pin state function.
surfacetemp2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: surfacetemp2.h:197
surfacetemp2_t::slave_address
uint8_t slave_address
Definition: surfacetemp2.h:176
surfacetemp2_cfg_t
Click configuration structure definition.
Definition: surfacetemp2.h:184
SURFACETEMP2_RETVAL
#define SURFACETEMP2_RETVAL
Definition: surfacetemp2.h:63
surfacetemp2_cfg_t::scl
pin_name_t scl
Definition: surfacetemp2.h:187
surfacetemp2_t::i2c
i2c_master_t i2c
Definition: surfacetemp2.h:172
surfacetemp2_cfg_t::i2c_address
uint8_t i2c_address
Definition: surfacetemp2.h:198
surfacetemp2_setup
uint8_t surfacetemp2_setup(surfacetemp2_t *ctx, uint8_t setup)
Setup function.
surfacetemp2_cfg_t::sda
pin_name_t sda
Definition: surfacetemp2.h:188
surfacetemp2_t::int_pin
digital_in_t int_pin
Definition: surfacetemp2.h:168
surfacetemp2_t::pwm
digital_in_t pwm
Definition: surfacetemp2.h:167
surfacetemp2_set_hys_val
void surfacetemp2_set_hys_val(surfacetemp2_t *ctx, uint8_t hys_val)
Set Hysteresis function.
surfacetemp2_get_int_pin
uint8_t surfacetemp2_get_int_pin(surfacetemp2_t *ctx)
Get INT pin state function.
surfacetemp2_soft_reset
void surfacetemp2_soft_reset(surfacetemp2_t *ctx)
Software Reset function.
surfacetemp2_cfg_t::pwm
pin_name_t pwm
Definition: surfacetemp2.h:192
surfacetemp2_t
Click ctx object definition.
Definition: surfacetemp2.h:164
surfacetemp2_generic_write
void surfacetemp2_generic_write(surfacetemp2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
surfacetemp2_generic_read
void surfacetemp2_generic_read(surfacetemp2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
surfacetemp2_set_high_trsh
void surfacetemp2_set_high_trsh(surfacetemp2_t *ctx, float trsh)
Set Over Temperature Threshold function.
surfacetemp2_get_temperature
float surfacetemp2_get_temperature(surfacetemp2_t *ctx)
Get Temperature function.
surfacetemp2_set_crit_trsh
void surfacetemp2_set_crit_trsh(surfacetemp2_t *ctx, float trsh)
Set Critical Temperature Threshold function.
surfacetemp2_cfg_t::int_pin
pin_name_t int_pin
Definition: surfacetemp2.h:193
surfacetemp2_set_low_trsh
void surfacetemp2_set_low_trsh(surfacetemp2_t *ctx, float trsh)
Set Under Temperature Threshold function.
surfacetemp2_init
SURFACETEMP2_RETVAL surfacetemp2_init(surfacetemp2_t *ctx, surfacetemp2_cfg_t *cfg)
Initialization function.
surfacetemp2_cfg_setup
void surfacetemp2_cfg_setup(surfacetemp2_cfg_t *cfg)
Config Object Initialization function.