surfacetemp 2.0.0.0
surfacetemp.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 SURFACETEMP_H
36#define SURFACETEMP_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 SURFACETEMP_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
77#define SURFACETEMP_RETVAL uint8_t
78
79#define SURFACETEMP_OK 0x00
80#define SURFACETEMP_INIT_ERROR 0xFF
87#define DEVICE_OK 0
88#define DEVICE_ERROR 1
95#define SURFACETEMP_SLAVE_DEVICE_ADDR_0_0 0x48
96#define SURFACETEMP_SLAVE_DEVICE_ADDR_0_1 0x49
97#define SURFACETEMP_SLAVE_DEVICE_ADDR_1_0 0x4A
98#define SURFACETEMP_SLAVE_DEVICE_ADDR_1_1 0x4B
105#define SURFACETEMP_REG_TEMP_MSB 0x00
106#define SURFACETEMP_REG_TEMP_LSB 0x01
107#define SURFACETEMP_REG_STATUS 0x02
108#define SURFACETEMP_REG_CONFIG 0x03
109#define SURFACETEMP_REG_T_HIGH_SETP_MSB 0x04
110#define SURFACETEMP_REG_T_HIGH_SETP_LSB 0x05
111#define SURFACETEMP_REG_T_LOW_SETP_MSB 0x06
112#define SURFACETEMP_REG_T_LOW_SETP_LSB 0x07
113#define SURFACETEMP_REG_T_CRIT_SETP_MSB 0x08
114#define SURFACETEMP_REG_T_CRIT_SETP_LSB 0x09
115#define SURFACETEMP_REG_T_HYST_SETP 0x0A
116#define SURFACETEMP_REG_ID 0x0B
117#define SURFACETEMP_REG_SOFT_RESET 0x2F
124#define SURFACETEMP_T_LOW_MASK 0x10
125#define SURFACETEMP_T_HIGH_MASK 0x20
126#define SURFACETEMP_T_CRIT_MASK 0x40
127#define SURFACETEMP_RDY_MASK 0x80
130 // End group macro
131// --------------------------------------------------------------- PUBLIC TYPES
140typedef struct
141{
142 // Output pins
143
144 digital_out_t rst;
145 digital_out_t pwm;
146
147 // Modules
148
149 i2c_master_t i2c;
150
151 // ctx variable
152
154
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 pin_name_t rst;
170 pin_name_t pwm;
171
172 // static variable
173
174 uint32_t i2c_speed;
175 uint8_t i2c_address;
176
178
179 // End types group
180// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
181
187#ifdef __cplusplus
188extern "C"{
189#endif
190
200
210
219
230void surfacetemp_generic_write ( surfacetemp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
231
243void surfacetemp_generic_read ( surfacetemp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
244
256
265
276
287
299uint8_t surfacetemp_set_high_threshold ( surfacetemp_t *ctx, float high_threshold );
300
312uint8_t surfacetemp_set_low_threshold ( surfacetemp_t *ctx, float high_threshold );
313
325uint8_t surfacetemp_set_critical_threshold ( surfacetemp_t *ctx, float high_threshold );
326
338uint8_t surfacetemp_set_hysteresis ( surfacetemp_t *ctx, uint8_t hysteresis );
339
357
358#ifdef __cplusplus
359}
360#endif
361#endif // _SURFACETEMP_H_
362
363 // End public_function group
365
366// ------------------------------------------------------------------------- END
#define SURFACETEMP_RETVAL
Definition surfacetemp.h:77
float surfacetemp_get_temperature(surfacetemp_t *ctx)
Getting temperature value.
void surfacetemp_soft_reset(surfacetemp_t *ctx)
Soft reset.
uint8_t surfacetemp_get_pwm_pin(surfacetemp_t *ctx)
Getting PWM pin state.
void surfacetemp_default_cfg(surfacetemp_t *ctx)
Click Default Configuration function.
void surfacetemp_generic_read(surfacetemp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void surfacetemp_generic_write(surfacetemp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint8_t surfacetemp_setup(surfacetemp_t *ctx)
Device initialization.
uint8_t surfacetemp_set_low_threshold(surfacetemp_t *ctx, float high_threshold)
Setting low threshold limit.
uint8_t surfacetemp_get_status(surfacetemp_t *ctx)
Getting device status.
void surfacetemp_cfg_setup(surfacetemp_cfg_t *cfg)
Config Object Initialization function.
SURFACETEMP_RETVAL surfacetemp_init(surfacetemp_t *ctx, surfacetemp_cfg_t *cfg)
Initialization function.
uint8_t surfacetemp_set_hysteresis(surfacetemp_t *ctx, uint8_t hysteresis)
Setting hysteresis value.
uint8_t surfacetemp_set_critical_threshold(surfacetemp_t *ctx, float high_threshold)
Setting critical threshold limit.
uint8_t surfacetemp_set_high_threshold(surfacetemp_t *ctx, float high_threshold)
Setting high threshold limit.
Click configuration structure definition.
Definition surfacetemp.h:161
uint32_t i2c_speed
Definition surfacetemp.h:174
pin_name_t scl
Definition surfacetemp.h:164
pin_name_t pwm
Definition surfacetemp.h:170
pin_name_t sda
Definition surfacetemp.h:165
pin_name_t rst
Definition surfacetemp.h:169
uint8_t i2c_address
Definition surfacetemp.h:175
Click ctx object definition.
Definition surfacetemp.h:141
digital_out_t pwm
Definition surfacetemp.h:145
i2c_master_t i2c
Definition surfacetemp.h:149
digital_out_t rst
Definition surfacetemp.h:144
uint8_t slave_address
Definition surfacetemp.h:153