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 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define SURFACETEMP_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
66  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
67 
73 #define SURFACETEMP_RETVAL uint8_t
74 
75 #define SURFACETEMP_OK 0x00
76 #define SURFACETEMP_INIT_ERROR 0xFF
77 
83 #define DEVICE_OK 0
84 #define DEVICE_ERROR 1
85 
91 #define SURFACETEMP_SLAVE_DEVICE_ADDR_0_0 0x48
92 #define SURFACETEMP_SLAVE_DEVICE_ADDR_0_1 0x49
93 #define SURFACETEMP_SLAVE_DEVICE_ADDR_1_0 0x4A
94 #define SURFACETEMP_SLAVE_DEVICE_ADDR_1_1 0x4B
95 
101 #define SURFACETEMP_REG_TEMP_MSB 0x00
102 #define SURFACETEMP_REG_TEMP_LSB 0x01
103 #define SURFACETEMP_REG_STATUS 0x02
104 #define SURFACETEMP_REG_CONFIG 0x03
105 #define SURFACETEMP_REG_T_HIGH_SETP_MSB 0x04
106 #define SURFACETEMP_REG_T_HIGH_SETP_LSB 0x05
107 #define SURFACETEMP_REG_T_LOW_SETP_MSB 0x06
108 #define SURFACETEMP_REG_T_LOW_SETP_LSB 0x07
109 #define SURFACETEMP_REG_T_CRIT_SETP_MSB 0x08
110 #define SURFACETEMP_REG_T_CRIT_SETP_LSB 0x09
111 #define SURFACETEMP_REG_T_HYST_SETP 0x0A
112 #define SURFACETEMP_REG_ID 0x0B
113 #define SURFACETEMP_REG_SOFT_RESET 0x2F
114 
120 #define SURFACETEMP_T_LOW_MASK 0x10
121 #define SURFACETEMP_T_HIGH_MASK 0x20
122 #define SURFACETEMP_T_CRIT_MASK 0x40
123 #define SURFACETEMP_RDY_MASK 0x80
124  // End group macro
127 // --------------------------------------------------------------- PUBLIC TYPES
136 typedef struct
137 {
138  // Output pins
139 
140  digital_out_t rst;
141  digital_out_t pwm;
142 
143  // Modules
144 
145  i2c_master_t i2c;
146 
147  // ctx variable
148 
149  uint8_t slave_address;
150 
151 } surfacetemp_t;
152 
156 typedef struct
157 {
158  // Communication gpio pins
159 
160  pin_name_t scl;
161  pin_name_t sda;
162 
163  // Additional gpio pins
164 
165  pin_name_t rst;
166  pin_name_t pwm;
167 
168  // static variable
169 
170  uint32_t i2c_speed;
171  uint8_t i2c_address;
172 
174  // End types group
176 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
177 
183 #ifdef __cplusplus
184 extern "C"{
185 #endif
186 
196 
206 
215 
226 void surfacetemp_generic_write ( surfacetemp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
227 
239 void surfacetemp_generic_read ( surfacetemp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
240 
252 
261 
272 
283 
295 uint8_t surfacetemp_set_high_threshold ( surfacetemp_t *ctx, float high_threshold );
296 
308 uint8_t surfacetemp_set_low_threshold ( surfacetemp_t *ctx, float high_threshold );
309 
321 uint8_t surfacetemp_set_critical_threshold ( surfacetemp_t *ctx, float high_threshold );
322 
334 uint8_t surfacetemp_set_hysteresis ( surfacetemp_t *ctx, uint8_t hysteresis );
335 
353 
354 #ifdef __cplusplus
355 }
356 #endif
357 #endif // _SURFACETEMP_H_
358  // End public_function group
361 
362 // ------------------------------------------------------------------------- END
surfacetemp_get_temperature
float surfacetemp_get_temperature(surfacetemp_t *ctx)
Getting temperature value.
surfacetemp_t::pwm
digital_out_t pwm
Definition: surfacetemp.h:141
surfacetemp_t::slave_address
uint8_t slave_address
Definition: surfacetemp.h:149
surfacetemp_t
Click ctx object definition.
Definition: surfacetemp.h:137
surfacetemp_generic_read
void surfacetemp_generic_read(surfacetemp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
surfacetemp_get_pwm_pin
uint8_t surfacetemp_get_pwm_pin(surfacetemp_t *ctx)
Getting PWM pin state.
surfacetemp_soft_reset
void surfacetemp_soft_reset(surfacetemp_t *ctx)
Soft reset.
surfacetemp_cfg_t::scl
pin_name_t scl
Definition: surfacetemp.h:160
surfacetemp_set_hysteresis
uint8_t surfacetemp_set_hysteresis(surfacetemp_t *ctx, uint8_t hysteresis)
Setting hysteresis value.
surfacetemp_generic_write
void surfacetemp_generic_write(surfacetemp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
surfacetemp_cfg_t
Click configuration structure definition.
Definition: surfacetemp.h:157
surfacetemp_set_critical_threshold
uint8_t surfacetemp_set_critical_threshold(surfacetemp_t *ctx, float high_threshold)
Setting critical threshold limit.
surfacetemp_init
SURFACETEMP_RETVAL surfacetemp_init(surfacetemp_t *ctx, surfacetemp_cfg_t *cfg)
Initialization function.
surfacetemp_cfg_setup
void surfacetemp_cfg_setup(surfacetemp_cfg_t *cfg)
Config Object Initialization function.
surfacetemp_set_high_threshold
uint8_t surfacetemp_set_high_threshold(surfacetemp_t *ctx, float high_threshold)
Setting high threshold limit.
surfacetemp_default_cfg
void surfacetemp_default_cfg(surfacetemp_t *ctx)
Click Default Configuration function.
surfacetemp_setup
uint8_t surfacetemp_setup(surfacetemp_t *ctx)
Device initialization.
surfacetemp_cfg_t::sda
pin_name_t sda
Definition: surfacetemp.h:161
surfacetemp_cfg_t::pwm
pin_name_t pwm
Definition: surfacetemp.h:166
SURFACETEMP_RETVAL
#define SURFACETEMP_RETVAL
Definition: surfacetemp.h:73
surfacetemp_set_low_threshold
uint8_t surfacetemp_set_low_threshold(surfacetemp_t *ctx, float high_threshold)
Setting low threshold limit.
surfacetemp_cfg_t::rst
pin_name_t rst
Definition: surfacetemp.h:165
surfacetemp_get_status
uint8_t surfacetemp_get_status(surfacetemp_t *ctx)
Getting device status.
surfacetemp_cfg_t::i2c_address
uint8_t i2c_address
Definition: surfacetemp.h:171
surfacetemp_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: surfacetemp.h:170
surfacetemp_t::rst
digital_out_t rst
Definition: surfacetemp.h:140
surfacetemp_t::i2c
i2c_master_t i2c
Definition: surfacetemp.h:145