thermo14 2.2.0
thermo14.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 THERMO14_H
36#define THERMO14_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
57// -------------------------------------------------------------- PUBLIC MACROS
62
67#define THERMO14_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
70 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
71
72
77#define THERMO14_RETVAL uint8_t
78
79#define THERMO14_OK 0x00
80#define THERMO14_INIT_ERROR 0xFF
82
87#define THERMO14_I2C_ADR_VDD 0x38
88#define THERMO14_I2C_ADR_GND 0x3F
89#define THERMO14_ARA_ADR 0x0C
91
96#define THERMO14_WHOAMI 0x01
97#define THERMO14_TEMP_H_LIMIT 0x02
98#define THERMO14_TEMP_L_LIMIT 0x03
99#define THERMO14_CTL 0x04
100#define THERMO14_STAT 0x05
101#define THERMO14_TEMP_L_OUT 0x06
102#define THERMO14_TEMP_H_OUT 0x07
103#define THERMO14_SW_RST 0x0C
105
110#define THERMO14_CTL_LOW_ODR_ST 0x80
111#define THERMO14_CTL_BDU 0x40
112#define THERMO14_CTL_AVG_8 0x00
113#define THERMO14_CTL_AVG_4 0x10
114#define THERMO14_CTL_AVG_2 0x20
115#define THERMO14_CTL_AVG_1 0x30
116#define THERMO14_CTL_IF_ADR_INC 0x08
117#define THERMO14_CTL_FREERUN 0x04
118#define THERMO14_CTL_TIME_OUT_DIS 0x02
119#define THERMO14_CTL_ONE_SHOT 0x01
121
126#define THERMO14_SW_RST_RST_CMD 0x02
127#define THERMO14_SW_RST_LOW_ODR_EN 0x40
129 // End group macro
131// --------------------------------------------------------------- PUBLIC TYPES
136
140typedef struct
141{
142 // Input pins
143
144
145 digital_in_t int_pin;
146
147 // Modules
148
149 i2c_master_t i2c;
150
151 // ctx variable
152
154
155} thermo14_t;
156
160typedef struct
161{
162 // Communication gpio pins
163
164 pin_name_t scl;
165 pin_name_t sda;
166
167 // Additional gpio pins
168
169
170 pin_name_t int_pin;
171
172 // static variable
173
174 uint32_t i2c_speed;
175 uint8_t i2c_address;
176
178 // End types group
180
181// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
182
187
188#ifdef __cplusplus
189extern "C"{
190#endif
191
201
211
222void thermo14_generic_write ( thermo14_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
223
234void thermo14_generic_read ( thermo14_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
235
237
246
255
266
278float thermo14_raw_to_celsius ( thermo14_t *ctx, int16_t temp_raw );
279
290
303
312void thermo14_low_temp_trsh ( thermo14_t *ctx, float trsh_val );
313
322void thermo14_high_temp_trsh ( thermo14_t *ctx, float trsh_val );
323
324#ifdef __cplusplus
325}
326#endif
327#endif // _THERMO14_H_
328 // End public_function group
331
332// ------------------------------------------------------------------------- END
#define THERMO14_RETVAL
Definition thermo14.h:77
THERMO14_RETVAL thermo14_init(thermo14_t *ctx, thermo14_cfg_t *cfg)
Initialization function.
float thermo14_raw_to_celsius(thermo14_t *ctx, int16_t temp_raw)
Temperature Calculation function. ````````````````.
void thermo14_generic_read(thermo14_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
float thermo14_get_temperature(thermo14_t *ctx)
Get Temperature in Centigrade function.
void thermo14_default_cfg(thermo14_t *ctx)
void thermo14_cfg_setup(thermo14_cfg_t *cfg)
Config Object Initialization function.
int16_t thermo14_temp_raw_get(thermo14_t *ctx)
Get Raw Temperature Data function.
void thermo14_sensor_enable(thermo14_t *ctx)
Sensor enable function.
uint8_t thermo14_get_int(thermo14_t *ctx)
Get Interrupt state function.
void thermo14_generic_write(thermo14_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void thermo14_reset(thermo14_t *ctx)
Reset function.
void thermo14_low_temp_trsh(thermo14_t *ctx, float trsh_val)
Set the low temperature threshold value function.
void thermo14_high_temp_trsh(thermo14_t *ctx, float trsh_val)
Set the high temperature threshold value function.
Click configuration structure definition.
Definition thermo14.h:161
uint32_t i2c_speed
Definition thermo14.h:174
pin_name_t scl
Definition thermo14.h:164
pin_name_t int_pin
Definition thermo14.h:170
pin_name_t sda
Definition thermo14.h:165
uint8_t i2c_address
Definition thermo14.h:175
Click ctx object definition.
Definition thermo14.h:141
digital_in_t int_pin
Definition thermo14.h:145
i2c_master_t i2c
Definition thermo14.h:149
uint8_t slave_address
Definition thermo14.h:153