tempalarm 2.1.0.0
tempalarm.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 TEMPALARM_H
29#define TEMPALARM_H
30
31#ifdef __cplusplus
32extern "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_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
73#define TEMPALARM_REG_TEMP_LOCAL 0x00
74#define TEMPALARM_REG_TEMP_REMOTE_MSB 0x01
75#define TEMPALARM_REG_ALERT_STATUS 0x02
76#define TEMPALARM_REG_CONFIGURATION 0x03
77#define TEMPALARM_REG_CONV_PERIOD 0x04
78#define TEMPALARM_REG_THIGH_LIMIT_LOCAL 0x05
79#define TEMPALARM_REG_THIGH_LIMIT_REMOTE_MSB 0x07
80#define TEMPALARM_REG_TLOW_LIMIT_REMOTE_MSB 0x08
81#define TEMPALARM_REG_ONE_SHOT 0x0F
82#define TEMPALARM_REG_TEMP_REMOTE_LSB 0x10
83#define TEMPALARM_REG_REMOTE_OFFSET_MSB 0x11
84#define TEMPALARM_REG_REMOTE_OFFSET_LSB 0x12
85#define TEMPALARM_REG_THIGH_LIMIT_REMOTE_LSB 0x13
86#define TEMPALARM_REG_TLOW_LIMIT_REMOTE_LSB 0x14
87#define TEMPALARM_REG_ALERT_MASK 0x16
88#define TEMPALARM_REG_THIGH_CRIT_REMOTE 0x19
89#define TEMPALARM_REG_THIGH_CRIT_LOCAL 0x20
90#define TEMPALARM_REG_CRIT_HYSTERESIS 0x21
91#define TEMPALARM_REG_LOG1 0x2D
92#define TEMPALARM_REG_LOG2 0x2E
93#define TEMPALARM_REG_LOG3 0x2F
94#define TEMPALARM_REG_FILTER_ALERT_MODE 0xBF
95#define TEMPALARM_REG_CHIP_ID 0xFD
96#define TEMPALARM_REG_VENDOR_ID 0xFE
97#define TEMPALARM_REG_DEVICE_REV_ID 0xFF
98
99 // tempalarm_reg
100
115#define TEMPALARM_THIGH_LA_ALERT_DIS_MASK 0x80
116#define TEMPALARM_THIGH_LA_ALERT_ENABLE_MASK 0x80
117#define TEMPALARM_THIGH_RA_ALERT_DIS_MASK 0x10
118#define TEMPALARM_THIGH_RA_ALERT_ENABLE_MASK 0x00
119#define TEMPALARM_TLOW_RA_ALERT_DIS_MASK 0x08
120#define TEMPALARM_TLOW_RA_ALERT_ENABLE_MASK 0x00
121#define TEMPALARM_TCRIT_R_ALERT_DIS_MASK 0x02
122#define TEMPALARM_TCRIT_R_ALERT_ENABLE_MASK 0x00
123#define TEMPALARM_TCRIT_L_ALERT_DIS_MASK 0x01
124#define TEMPALARM_TCRIT_L_ALERT_ENABLE_MASK 0x00
125
130#define TEMPALARM_ADC_BUSY_MASK 0x80
131#define TEMPALARM_THIGH_LA_MASK 0x40
132#define TEMPALARM_THIGH_RA_MASK 0x10
133#define TEMPALARM_TLOW_RA_MASK 0x08
134#define TEMPALARM_REMOTE_DC_MASK 0x04
135#define TEMPALARM_TCRIT_R_MASK 0x02
136#define TEMPALARM_TCRIT_L_MASK 0x01
137
142#define TEMPALARM_FILTER_LEVEL_0_MASK 0x00
143#define TEMPALARM_FILTER_LEVEL_4_MASK 0x02
144#define TEMPALARM_FILTER_LEVEL_8_MASK 0x06
145#define TEMPALARM_INTERRUPT_ALERT_MODE 0x00
146#define TEMPALARM_COMPARATOR_MODE 0x01
147
152#define TEMPALARM_ALERT_DISABLED 0x80
153#define TEMPALARM_SHUTDOWN_MODE 0x40
154#define TEMPALARM_CONTINUOUS_MODE 0x00
155#define TEMPALARM_REMOTE_EN 0x04
156#define TEMPALARM_REMOTE_DIS 0x00
157#define TEMPALARM_WTC_EN 0x02
158#define TEMPALARM_WTC_DIS 0x00
159#define TEMPALARM_FAULT_QUE_EN 0x01
160#define TEMPALARM_FAULT_QUE_DIS 0x00
161
166#define TEMPALARM_CONVERSION_PERIOD_16S 0x00
167#define TEMPALARM_CONVERSION_PERIOD_8S 0x01
168#define TEMPALARM_CONVERSION_PERIOD_4S 0x02
169#define TEMPALARM_CONVERSION_PERIOD_2S 0x03
170#define TEMPALARM_CONVERSION_PERIOD_1S 0x04
171#define TEMPALARM_CONVERSION_PERIOD_500MS 0x05
172#define TEMPALARM_CONVERSION_PERIOD_250MS 0x06
173#define TEMPALARM_CONVERSION_PERIOD_125MS 0x07
174#define TEMPALARM_CONVERSION_PERIOD_62MS5 0x08
175
180#define TEMPALARM_PIN_STATE_HIGH 0x01
181#define TEMPALARM_PIN_STATE_LOW 0x00
182
187#define TEMPALARM_CHIP_ID 0x50
188#define TEMPALARM_VENDOR_ID 0x60
189
194#define TEMPALARM_TEMP_CLC 0.125f
195
201#define TEMPALARM_DEVICE_ADDRESS 0x4C
202
203 // tempalarm_set
204
219#define TEMPALARM_MAP_MIKROBUS( cfg, mikrobus ) \
220 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
221 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
222 cfg.tcr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
223 cfg.alr = MIKROBUS( mikrobus, MIKROBUS_INT )
224
225 // tempalarm_map
226 // tempalarm
227
232typedef struct
233{
234 // Input pins
235 digital_in_t tcr;
236 digital_in_t alr;
238 // Modules
239 i2c_master_t i2c;
241 // I2C slave address
245
250typedef struct
251{
252 pin_name_t scl;
253 pin_name_t sda;
255 pin_name_t tcr;
256 pin_name_t alr;
258 uint32_t i2c_speed;
259 uint8_t i2c_address;
262
273
290
305
319
334err_t tempalarm_generic_write ( tempalarm_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
335
350err_t tempalarm_generic_read ( tempalarm_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
351
362
373
387err_t tempalarm_write_reg ( tempalarm_t *ctx, uint8_t reg, uint8_t data_in );
388
402err_t tempalarm_read_reg ( tempalarm_t *ctx, uint8_t reg, uint8_t *data_out );
403
415err_t tempalarm_read_temperature ( tempalarm_t *ctx, int8_t *temperature );
416
428err_t tempalarm_read_remote_temp ( tempalarm_t *ctx, float *temperature );
429
441err_t tempalarm_set_crit_thigh ( tempalarm_t *ctx, int8_t max_temperature );
442
454err_t tempalarm_set_limit_thigh ( tempalarm_t *ctx, int8_t max_temperature );
455
467err_t tempalarm_set_alarm_low_limit ( tempalarm_t *ctx, float min_temperature );
468
480err_t tempalarm_set_alarm_high_limit ( tempalarm_t *ctx, float max_temperature );
481
493err_t tempalarm_get_alarms ( tempalarm_t *ctx, uint8_t *alarms );
494
495#ifdef __cplusplus
496}
497#endif
498#endif // TEMPALARM_H
499
500 // tempalarm
501
502// ------------------------------------------------------------------------ END
err_t tempalarm_write_reg(tempalarm_t *ctx, uint8_t reg, uint8_t data_in)
Temp Alarm register writing function.
err_t tempalarm_read_reg(tempalarm_t *ctx, uint8_t reg, uint8_t *data_out)
Temp Alarm register reading function.
void tempalarm_cfg_setup(tempalarm_cfg_t *cfg)
Temp Alarm configuration object setup function.
err_t tempalarm_set_limit_thigh(tempalarm_t *ctx, int8_t max_temperature)
Temp Alarm local sensor set limit high temperature function.
err_t tempalarm_read_remote_temp(tempalarm_t *ctx, float *temperature)
Temp Alarm remote sensor read temperature function.
err_t tempalarm_set_crit_thigh(tempalarm_t *ctx, int8_t max_temperature)
Temp Alarm local sensor set critical high temperature function.
err_t tempalarm_read_temperature(tempalarm_t *ctx, int8_t *temperature)
Temp Alarm local sensor read temperature function.
uint8_t tempalarm_get_tcr_pin(tempalarm_t *ctx)
Temp Alarm get critical temperature alert pin state function.
err_t tempalarm_default_cfg(tempalarm_t *ctx)
Temp Alarm default configuration function.
err_t tempalarm_generic_write(tempalarm_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Temp Alarm I2C writing function.
err_t tempalarm_generic_read(tempalarm_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Temp Alarm I2C reading function.
err_t tempalarm_get_alarms(tempalarm_t *ctx, uint8_t *alarms)
Temp Alarm read alarms state function.
err_t tempalarm_set_alarm_low_limit(tempalarm_t *ctx, float min_temperature)
Temp Alarm remote sensor set limit low temperature function.
uint8_t tempalarm_get_alr_pin(tempalarm_t *ctx)
Temp Alarm get alarm pin state function.
err_t tempalarm_init(tempalarm_t *ctx, tempalarm_cfg_t *cfg)
Temp Alarm initialization function.
err_t tempalarm_set_alarm_high_limit(tempalarm_t *ctx, float max_temperature)
Temp Alarm remote sensor set limit high temperature function.
Temp Alarm Click configuration object.
Definition tempalarm.h:251
pin_name_t alr
Definition tempalarm.h:256
uint32_t i2c_speed
Definition tempalarm.h:258
pin_name_t scl
Definition tempalarm.h:252
pin_name_t tcr
Definition tempalarm.h:255
pin_name_t sda
Definition tempalarm.h:253
uint8_t i2c_address
Definition tempalarm.h:259
Temp Alarm Click context object.
Definition tempalarm.h:233
digital_in_t tcr
Definition tempalarm.h:235
digital_in_t alr
Definition tempalarm.h:236
i2c_master_t i2c
Definition tempalarm.h:239
uint8_t slave_address
Definition tempalarm.h:242
tempalarm_return_value_t
Temp Alarm Click return value data.
Definition tempalarm.h:268
@ TEMPALARM_OK
Definition tempalarm.h:269
@ TEMPALARM_ERROR
Definition tempalarm.h:270