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
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 SURFACETEMP2_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
70 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
77#define SURFACETEMP2_RETVAL uint8_t
78
79#define SURFACETEMP2_OK 0x00
80#define SURFACETEMP2_INIT_ERROR 0xFF
87#define SURFACETEMP2_I2C_DEV_ADR_0_0 0x48
88#define SURFACETEMP2_I2C_DEV_ADR_0_1 0x49
89#define SURFACETEMP2_I2C_DEV_ADR_1_0 0x4A
90#define SURFACETEMP2_I2C_DEV_ADR_1_1 0x4B
97#define SURFACETEMP2_REG_TEMP_MSB 0x00
98#define SURFACETEMP2_REG_TEMP_LSB 0x01
99#define SURFACETEMP2_REG_STAT 0x02
100#define SURFACETEMP2_REG_CFG 0x03
101#define SURFACETEMP2_REG_T_HIGH_SETP_MSB 0x04
102#define SURFACETEMP2_REG_T_HIGH_SETP_LSB 0x05
103#define SURFACETEMP2_REG_T_LOW_SETP_MSB 0x06
104#define SURFACETEMP2_REG_T_LOW_SETP_LSB 0x07
105#define SURFACETEMP2_REG_T_CRIT_SETP_MSB 0x08
106#define SURFACETEMP2_REG_T_CRIT_SETP_LSB 0x09
107#define SURFACETEMP2_REG_T_HYST_SETP 0x0A
108#define SURFACETEMP2_REG_ID 0x0B
109#define SURFACETEMP2_REG_SOFT_RESET 0x2F
116#define SURFACETEMP2_STAT_T_LOW_MSK 0x10
117#define SURFACETEMP2_STAT_T_HIGH_MSK 0x20
118#define SURFACETEMP2_STAT_T_CRIT_MSK 0x40
119#define SURFACETEMP2_STAT_RDY_MSK 0x80
126#define SURFACETEMP2_CFG_FLT_Q_1 0x00
127#define SURFACETEMP2_CFG_FLT_Q_2 0x01
128#define SURFACETEMP2_CFG_FLT_Q_3 0x02
129#define SURFACETEMP2_CFG_FLT_Q_4 0x03
130#define SURFACETEMP2_CFG_CT_POL_ACT_H 0x04
131#define SURFACETEMP2_CFG_CT_POL_ACT_L 0x00
132#define SURFACETEMP2_CFG_INT_POL_ACT_H 0x08
133#define SURFACETEMP2_CFG_INT_POL_ACT_L 0x00
134#define SURFACETEMP2_CFG_INT_MODE 0x00
135#define SURFACETEMP2_CFG_CT_MODE 0x10
136#define SURFACETEMP2_CFG_OP_MODE_CONT 0x00
137#define SURFACETEMP2_CFG_OP_MODE_ONE_SHT 0x20
138#define SURFACETEMP2_CFG_OP_MODE_SPS 0x40
139#define SURFACETEMP2_CFG_OP_MODE_SHDN 0x60
140#define SURFACETEMP2_CFG_RES_13 0x00
141#define SURFACETEMP2_CFG_RES_16 0x80
148#define SURFACETEMP2_RES_13_BIT 0.0625
149#define SURFACETEMP2_RES_16_BIT 0.0078125
156#define SURFACETEMP2_DEV_ID_VAL 0xCB
163#define SURFACETEMP2_DEV_OK 0x00
164#define SURFACETEMP2_DEV_NOK 0x01
167 // End group macro
168// --------------------------------------------------------------- PUBLIC TYPES
177typedef struct
178{
179 // Input pins
180
181 digital_in_t pwm;
182 digital_in_t int_pin;
183
184 // Modules
185
186 i2c_master_t i2c;
187
188 // ctx variable
189
191
193
197typedef struct
198{
199 // Communication gpio pins
200
201 pin_name_t scl;
202 pin_name_t sda;
203
204 // Additional gpio pins
205
206 pin_name_t pwm;
207 pin_name_t int_pin;
208
209 // static variable
210
211 uint32_t i2c_speed;
212 uint8_t i2c_address;
213
215
216 // End types group
217// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
218
224#ifdef __cplusplus
225extern "C"{
226#endif
227
237
246
257void surfacetemp2_generic_write ( surfacetemp2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
258
270void surfacetemp2_generic_read ( surfacetemp2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
271
281
295uint8_t surfacetemp2_setup ( surfacetemp2_t *ctx, uint8_t setup );
296
306void surfacetemp2_set_hys_val ( surfacetemp2_t *ctx, uint8_t hys_val );
307
319
329
339
349
362
375
376#ifdef __cplusplus
377}
378#endif
379#endif // _SURFACETEMP2_H_
380
381 // End public_function group
383
384// ------------------------------------------------------------------------- END
#define SURFACETEMP2_RETVAL
Definition surfacetemp2.h:77
void surfacetemp2_generic_write(surfacetemp2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint8_t surfacetemp2_get_ct_pin(surfacetemp2_t *ctx)
Get CT pin state function.
void surfacetemp2_cfg_setup(surfacetemp2_cfg_t *cfg)
Config Object Initialization function.
uint8_t surfacetemp2_setup(surfacetemp2_t *ctx, uint8_t setup)
Setup function.
void surfacetemp2_soft_reset(surfacetemp2_t *ctx)
Software Reset function.
void surfacetemp2_generic_read(surfacetemp2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void surfacetemp2_set_hys_val(surfacetemp2_t *ctx, uint8_t hys_val)
Set Hysteresis function.
uint8_t surfacetemp2_get_int_pin(surfacetemp2_t *ctx)
Get INT pin state function.
float surfacetemp2_get_temperature(surfacetemp2_t *ctx)
Get Temperature function.
void surfacetemp2_set_high_trsh(surfacetemp2_t *ctx, float trsh)
Set Over Temperature Threshold function.
void surfacetemp2_set_low_trsh(surfacetemp2_t *ctx, float trsh)
Set Under Temperature Threshold function.
SURFACETEMP2_RETVAL surfacetemp2_init(surfacetemp2_t *ctx, surfacetemp2_cfg_t *cfg)
Initialization function.
void surfacetemp2_set_crit_trsh(surfacetemp2_t *ctx, float trsh)
Set Critical Temperature Threshold function.
Click configuration structure definition.
Definition surfacetemp2.h:198
uint32_t i2c_speed
Definition surfacetemp2.h:211
pin_name_t scl
Definition surfacetemp2.h:201
pin_name_t int_pin
Definition surfacetemp2.h:207
pin_name_t pwm
Definition surfacetemp2.h:206
pin_name_t sda
Definition surfacetemp2.h:202
uint8_t i2c_address
Definition surfacetemp2.h:212
Click ctx object definition.
Definition surfacetemp2.h:178
digital_in_t pwm
Definition surfacetemp2.h:181
digital_in_t int_pin
Definition surfacetemp2.h:182
i2c_master_t i2c
Definition surfacetemp2.h:186
uint8_t slave_address
Definition surfacetemp2.h:190