remotetemp 2.0.0.0
remotetemp.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 REMOTETEMP_H
36#define REMOTETEMP_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 REMOTETEMP_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.thm = MIKROBUS( mikrobus, MIKROBUS_AN ); \
70 cfg.alr = MIKROBUS( mikrobus, MIKROBUS_INT )
77#define REMOTETEMP_RETVAL uint8_t
78
79#define REMOTETEMP_OK 0x00
80#define REMOTETEMP_INIT_ERROR 0xFF
87#define REMOTETEMP_DEVICE_ADDRESS_4p7 0x7C
88#define REMOTETEMP_DEVICE_ADDRESS_6p8 0x5C
89#define REMOTETEMP_DEVICE_ADDRESS_10 0x4C
90#define REMOTETEMP_DEVICE_ADDRESS_15 0x6C
91#define REMOTETEMP_DEVICE_ADDRESS_22 0x1C
92#define REMOTETEMP_DEVICE_ADDRESS_33 0x3C
99#define REMOTETEMP_RANGE_0_127 0x00
100#define REMOTETEMP_RANGE_m64_191 0x01
107#define REMOTETEMP_EXT_DIODE_1 0x01
108#define REMOTETEMP_EXT_DIODE_2 0x02
109#define REMOTETEMP_EXT_DIODE_3 0x03
110#define REMOTETEMP_EXT_DIODE_4 0x04
117#define REMOTETEMP_STATUS 0x02
118#define REMOTETEMP_CONFIG 0x09
119#define REMOTETEMP_CONVERT 0x0A
120#define REMOTETEMP_INT_DIODE_HIGH_LIMIT 0x0B
121#define REMOTETEMP_INT_DIODE_LOW_LIMIT 0x0C
122#define REMOTETEMP_EXT1_HIGH_LIMIT_HIGH_BYTE 0x0D
123#define REMOTETEMP_EXT1_LOW_LIMIT_HIGH_BYTE 0x0E
124#define REMOTETEMP_ONE_SHOT 0x0F
125#define REMOTETEMP_SCRTCHPD1 0x11
126#define REMOTETEMP_SCRTCHPD2 0x12
127#define REMOTETEMP_EXT1_HIGH_LIMIT_LOW_BYTE 0x13
128#define REMOTETEMP_EXT1_LOW_LIMIT_LOW_BYTE 0x14
129#define REMOTETEMP_EXT2_HIGH_LIMIT_HIGH_BYTE 0x15
130#define REMOTETEMP_EXT2_LOW_LIMIT_HIGH_BYTE 0x16
131#define REMOTETEMP_EXT2_HIGH_LIMIT_LOW_BYTE 0x17
132#define REMOTETEMP_EXT2_LOW_LIMIT_LOW_BYTE 0x18
133#define REMOTETEMP_EXT1_THERM_LIMIT 0x19
134#define REMOTETEMP_EXT2_THERM_LIMIT 0x1A
135#define REMOTETEMP_EXTERNAL_DIODE_FAULT_STATUS 0x1B
136#define REMOTETEMP_DIODE_FAULT_MASK 0x1F
137#define REMOTETEMP_INT_DIODE_THERM_LIMIT 0x20
138#define REMOTETEMP_THRM_HYS 0x21
139#define REMOTETEMP_CONSEC_ALERT 0x22
140#define REMOTETEMP_EXT1_BETA_CONFIG 0x25
141#define REMOTETEMP_EXT2_BETA_CONFIG 0x26
142#define REMOTETEMP_EXT1_IDEALITY_FACTOR 0x27
143#define REMOTETEMP_EXT2_IDEALITY_FACTOR 0x28
144#define REMOTETEMP_EXT3_HIGH_LIMIT_HIGH_BYTE 0x2C
145#define REMOTETEMP_EXT3_LOW_LIMIT_HIGH_BYTE 0x2D
146#define REMOTETEMP_EXT3_HIGH_LIMIT_LOW_BYTE 0x2E
147#define REMOTETEMP_EXT3_LOW_LIMIT_LOW_BYTE 0x2F
148#define REMOTETEMP_EXT3_THERM_LIMIT 0x30
149#define REMOTETEMP_EXT3_IDEALITY_FACTOR 0x31
150#define REMOTETEMP_EXT4_HIGH_LIMIT_HIGH_BYTE 0x34
151#define REMOTETEMP_EXT4_LOW_LIMIT_HIGH_BYTE 0x35
152#define REMOTETEMP_EXT4_HIGH_LIMIT_LOW_BYTE 0x36
153#define REMOTETEMP_EXT4_LOW_LIMIT_LOW_BYTE 0x37
154#define REMOTETEMP_EXT4_THERM_LIMIT 0x38
155#define REMOTETEMP_EXT4_IDEALITY_FACTOR 0x39
156#define REMOTETEMP_HIGH_LIMIT_STATUS 0x3A
157#define REMOTETEMP_LOW_LIMIT_STATUS 0x3B
158#define REMOTETEMP_THERM_LIMIT_STATUS 0x3C
159#define REMOTETEMP_ROC_GAIN 0x3D
160#define REMOTETEMP_ROC_CONFIG 0x3E
161#define REMOTETEMP_ROC_STATUS 0x3F
162#define REMOTETEMP_R1_RESH 0x40
163#define REMOTETEMP_R1_LIMH 0x41
164#define REMOTETEMP_R1_LIML 0x42
165#define REMOTETEMP_R1_SMPL 0x43
166#define REMOTETEMP_R2_RESH 0x44
167#define REMOTETEMP_R23_RESL 0x45
168#define REMOTETEMP_R2_LIMH 0x46
169#define REMOTETEMP_R2_LIML 0x47
170#define REMOTETEMP_R2_SMPL 0x48
171#define REMOTETEMP_PER_MAXT1L 0x4A
172#define REMOTETEMP_PER_MAXTH 0x4B
173#define REMOTETEMP_PER_MAXT23L 0x4C
174#define REMOTETEMP_GBL_MAXT1H 0x4D
175#define REMOTETEMP_GBL_MAXT1L 0x4E
176#define REMOTETEMP_GBL_MAXT2H 0x4F
177#define REMOTETEMP_GBL_MAXT2L 0x50
178#define REMOTETEMP_FILTER_SEL 0x51
179#define REMOTETEMP_INT_HIGH_BYTE 0x60
180#define REMOTETEMP_INT_LOW_BYTE 0x61
181#define REMOTETEMP_EXT1_HIGH_BYTE 0x62
182#define REMOTETEMP_EXT1_LOW_BYTE 0x63
183#define REMOTETEMP_EXT2_HIGH_BYTE 0x64
184#define REMOTETEMP_EXT2_LOW_BYTE 0x65
185#define REMOTETEMP_EXT3_HIGH_BYTE 0x66
186#define REMOTETEMP_EXT3_LOW_BYTE 0x67
187#define REMOTETEMP_EXT4_HIGH_BYTE 0x68
188#define REMOTETEMP_EXT4_LOW_BYTE 0x69
189#define REMOTETEMP_HOTTEST_DIODE_HIGH_BYTE 0x6A
190#define REMOTETEMP_HOTTEST_DIODE_LOW_BYTE 0x6B
191#define REMOTETEMP_HOTTEST_STATUS 0x6C
192#define REMOTETEMP_HOTTEST_CONFIG 0x6D
193#define REMOTETEMP_PRODUCT_ID 0xFD
194#define REMOTETEMP_MANUFACTURER_ID 0xFE
195#define REMOTETEMP_REVISION 0xFF
198 // End group macro
199// --------------------------------------------------------------- PUBLIC TYPES
208typedef struct
209{
210 // Input pins
211
212 digital_in_t thm;
213 digital_in_t alr;
214
215 // Modules
216
217 i2c_master_t i2c;
218
219 // ctx variable
220
222
223 uint8_t range_set;
224
226
230typedef struct
231{
232 // Communication gpio pins
233
234 pin_name_t scl;
235 pin_name_t sda;
236
237 // Additional gpio pins
238
239 pin_name_t thm;
240 pin_name_t alr;
241
242 // static variable
243
244 uint32_t i2c_speed;
245 uint8_t i2c_address;
246
248
249 // End variable group
250// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
251
257#ifdef __cplusplus
258extern "C"{
259#endif
260
270
280
289
300void remotetemp_generic_write ( remotetemp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
301
313void remotetemp_generic_read ( remotetemp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
314
315
327
339
351uint8_t remotetemp_set_range( remotetemp_t *ctx, uint8_t range_setting );
352
365void remotetemp_read ( remotetemp_t *ctx, uint8_t register_address, uint8_t * read_buffer, uint8_t n_bytes );
366
379void remotetemp_write ( remotetemp_t *ctx, uint8_t register_address, uint8_t * register_values, uint8_t n_bytes );
380
391void remotetemp_set_int_diode_high_limit ( remotetemp_t *ctx, int16_t limit_value );
392
403void remotetemp_set_int_diode_low_limit ( remotetemp_t *ctx, int16_t limit_value );
404
416void remotetemp_set_ext_diode_high_limit ( remotetemp_t *ctx, int16_t limit_value, uint8_t diode );
417
429void remotetemp_set_ext_diode_low_limit ( remotetemp_t *ctx, int16_t limit_value, uint8_t diode );
430
442void remotetemp_set_ext_diode_therm_limit ( remotetemp_t *ctx, int16_t limit_value, uint8_t diode );
443
454void remotetemp_set_int_diode_therm_limit ( remotetemp_t *ctx, int16_t limit_value );
455
466
477float remotetemp_get_external_diode ( remotetemp_t *ctx, uint8_t diode );
478
489
490#ifdef __cplusplus
491}
492#endif
493#endif // _REMOTETEMP_H_
494
495 // End public_function group
497
498// ------------------------------------------------------------------------- END
#define REMOTETEMP_RETVAL
Definition remotetemp.h:77
uint8_t remotetemp_int_get(remotetemp_t *ctx)
Getting state of INT pin.
void remotetemp_cfg_setup(remotetemp_cfg_t *cfg)
Config Object Initialization function.
void remotetemp_set_int_diode_low_limit(remotetemp_t *ctx, int16_t limit_value)
Setting Internal diode low limit.
void remotetemp_generic_write(remotetemp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void remotetemp_generic_read(remotetemp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
float remotetemp_get_external_diode(remotetemp_t *ctx, uint8_t diode)
Getting external diode temperature value.
void remotetemp_write(remotetemp_t *ctx, uint8_t register_address, uint8_t *register_values, uint8_t n_bytes)
Setting register content.
void remotetemp_set_ext_diode_therm_limit(remotetemp_t *ctx, int16_t limit_value, uint8_t diode)
Setting external diodes thermal limits.
void remotetemp_set_ext_diode_low_limit(remotetemp_t *ctx, int16_t limit_value, uint8_t diode)
Setting external diodes low limit.
uint8_t remotetemp_an_get(remotetemp_t *ctx)
Getting state of AN pin.
void remotetemp_default_cfg(remotetemp_t *ctx)
Click Default Configuration function.
void remotetemp_set_int_diode_therm_limit(remotetemp_t *ctx, int16_t limit_value)
Setting internal diodes thermal limits.
void remotetemp_set_ext_diode_high_limit(remotetemp_t *ctx, int16_t limit_value, uint8_t diode)
Setting external diodes high limit.
void remotetemp_read(remotetemp_t *ctx, uint8_t register_address, uint8_t *read_buffer, uint8_t n_bytes)
Reads register content.
float remotetemp_get_hottest_diode(remotetemp_t *ctx)
Getting hottest diode temperature value.
void remotetemp_set_int_diode_high_limit(remotetemp_t *ctx, int16_t limit_value)
Setting Internal diode high limit.
float remotetemp_get_internal_diode(remotetemp_t *ctx)
Getting internal diode temperature value.
uint8_t remotetemp_set_range(remotetemp_t *ctx, uint8_t range_setting)
Setting temperature range.
REMOTETEMP_RETVAL remotetemp_init(remotetemp_t *ctx, remotetemp_cfg_t *cfg)
Initialization function.
Click configuration structure definition.
Definition remotetemp.h:231
pin_name_t alr
Definition remotetemp.h:240
uint32_t i2c_speed
Definition remotetemp.h:244
pin_name_t thm
Definition remotetemp.h:239
pin_name_t scl
Definition remotetemp.h:234
pin_name_t sda
Definition remotetemp.h:235
uint8_t i2c_address
Definition remotetemp.h:245
Click ctx object definition.
Definition remotetemp.h:209
uint8_t range_set
Definition remotetemp.h:223
digital_in_t alr
Definition remotetemp.h:213
i2c_master_t i2c
Definition remotetemp.h:217
digital_in_t thm
Definition remotetemp.h:212
uint8_t slave_address
Definition remotetemp.h:221