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
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_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  // 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  // 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  // tempalarm_map // tempalarm
227 
232 typedef 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
242  uint8_t slave_address;
244 } tempalarm_t;
245 
250 typedef 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 
267 typedef enum
268 {
270  TEMPALARM_ERROR = -1
271 
273 
290 
305 
319 
334 err_t tempalarm_generic_write ( tempalarm_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
335 
350 err_t tempalarm_generic_read ( tempalarm_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
351 
362 
373 
387 err_t tempalarm_write_reg ( tempalarm_t *ctx, uint8_t reg, uint8_t data_in );
388 
402 err_t tempalarm_read_reg ( tempalarm_t *ctx, uint8_t reg, uint8_t *data_out );
403 
415 err_t tempalarm_read_temperature ( tempalarm_t *ctx, int8_t *temperature );
416 
428 err_t tempalarm_read_remote_temp ( tempalarm_t *ctx, float *temperature );
429 
441 err_t tempalarm_set_crit_thigh ( tempalarm_t *ctx, int8_t max_temperature );
442 
454 err_t tempalarm_set_limit_thigh ( tempalarm_t *ctx, int8_t max_temperature );
455 
467 err_t tempalarm_set_alarm_low_limit ( tempalarm_t *ctx, float min_temperature );
468 
480 err_t tempalarm_set_alarm_high_limit ( tempalarm_t *ctx, float max_temperature );
481 
493 err_t tempalarm_get_alarms ( tempalarm_t *ctx, uint8_t *alarms );
494 
495 #ifdef __cplusplus
496 }
497 #endif
498 #endif // TEMPALARM_H
499  // tempalarm
501 
502 // ------------------------------------------------------------------------ END
tempalarm_write_reg
err_t tempalarm_write_reg(tempalarm_t *ctx, uint8_t reg, uint8_t data_in)
Temp Alarm register writing function.
tempalarm_cfg_t
Temp Alarm Click configuration object.
Definition: tempalarm.h:251
tempalarm_t::tcr
digital_in_t tcr
Definition: tempalarm.h:235
tempalarm_t::i2c
i2c_master_t i2c
Definition: tempalarm.h:239
tempalarm_t::alr
digital_in_t alr
Definition: tempalarm.h:236
tempalarm_init
err_t tempalarm_init(tempalarm_t *ctx, tempalarm_cfg_t *cfg)
Temp Alarm initialization function.
tempalarm_t::slave_address
uint8_t slave_address
Definition: tempalarm.h:242
tempalarm_cfg_t::scl
pin_name_t scl
Definition: tempalarm.h:252
tempalarm_set_limit_thigh
err_t tempalarm_set_limit_thigh(tempalarm_t *ctx, int8_t max_temperature)
Temp Alarm local sensor set limit high temperature function.
tempalarm_read_temperature
err_t tempalarm_read_temperature(tempalarm_t *ctx, int8_t *temperature)
Temp Alarm local sensor read temperature function.
tempalarm_generic_write
err_t tempalarm_generic_write(tempalarm_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Temp Alarm I2C writing function.
tempalarm_set_alarm_high_limit
err_t tempalarm_set_alarm_high_limit(tempalarm_t *ctx, float max_temperature)
Temp Alarm remote sensor set limit high temperature function.
tempalarm_cfg_t::tcr
pin_name_t tcr
Definition: tempalarm.h:255
TEMPALARM_OK
@ TEMPALARM_OK
Definition: tempalarm.h:269
tempalarm_cfg_t::sda
pin_name_t sda
Definition: tempalarm.h:253
tempalarm_return_value_t
tempalarm_return_value_t
Temp Alarm Click return value data.
Definition: tempalarm.h:268
tempalarm_get_tcr_pin
uint8_t tempalarm_get_tcr_pin(tempalarm_t *ctx)
Temp Alarm get critical temperature alert pin state function.
tempalarm_default_cfg
err_t tempalarm_default_cfg(tempalarm_t *ctx)
Temp Alarm default configuration function.
tempalarm_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: tempalarm.h:258
tempalarm_t
Temp Alarm Click context object.
Definition: tempalarm.h:233
TEMPALARM_ERROR
@ TEMPALARM_ERROR
Definition: tempalarm.h:270
tempalarm_read_remote_temp
err_t tempalarm_read_remote_temp(tempalarm_t *ctx, float *temperature)
Temp Alarm remote sensor read temperature function.
tempalarm_set_crit_thigh
err_t tempalarm_set_crit_thigh(tempalarm_t *ctx, int8_t max_temperature)
Temp Alarm local sensor set critical high temperature function.
tempalarm_get_alarms
err_t tempalarm_get_alarms(tempalarm_t *ctx, uint8_t *alarms)
Temp Alarm read alarms state function.
tempalarm_cfg_t::alr
pin_name_t alr
Definition: tempalarm.h:256
tempalarm_cfg_setup
void tempalarm_cfg_setup(tempalarm_cfg_t *cfg)
Temp Alarm configuration object setup function.
tempalarm_read_reg
err_t tempalarm_read_reg(tempalarm_t *ctx, uint8_t reg, uint8_t *data_out)
Temp Alarm register reading function.
tempalarm_get_alr_pin
uint8_t tempalarm_get_alr_pin(tempalarm_t *ctx)
Temp Alarm get alarm pin state function.
tempalarm_cfg_t::i2c_address
uint8_t i2c_address
Definition: tempalarm.h:259
tempalarm_set_alarm_low_limit
err_t tempalarm_set_alarm_low_limit(tempalarm_t *ctx, float min_temperature)
Temp Alarm remote sensor set limit low temperature function.
tempalarm_generic_read
err_t tempalarm_generic_read(tempalarm_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Temp Alarm I2C reading function.