thermostat 2.0.0.0
thermostat.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 THERMOSTAT_H
36#define THERMOSTAT_H
37
38#include "drv_digital_out.h"
39#include "drv_digital_in.h"
40#include "drv_i2c_master.h"
41
42
43// -------------------------------------------------------------- PUBLIC MACROS
53#define THERMOSTAT_MAP_MIKROBUS( cfg, mikrobus ) \
54 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
57 cfg.te = MIKROBUS( mikrobus, MIKROBUS_CS )
64#define THERMOSTAT_RETVAL uint8_t
65
66#define THERMOSTAT_OK 0x00
67#define THERMOSTAT_INIT_ERROR 0xFF
74#define THERMOSTAT_I2C_ADDRESS_0 0x48
75#define THERMOSTAT_I2C_ADDRESS_1 0x49
76#define THERMOSTAT_I2C_ADDRESS_2 0x4A
77#define THERMOSTAT_I2C_ADDRESS_3 0x4B
84#define THERMOSTAT_REG_TEMP_OUT 0x00
85#define THERMOSTAT_REG_CONFIG 0x01
86#define THERMOSTAT_REG_TEMP_HYST 0x02
87#define THERMOSTAT_REG_TEMP_REF 0x03
88
89#define THERMOSTAT_CHECK_SIGN 0x80
90#define THERMOSTAT_DEFAULT_CONFIG 0x0000
91#define THERMOSTAT_MSB_BITS 0xFF00
92#define THERMOSTAT_LSB_BITS 0x00FF
93#define THERMOSTAT_START_RESULT 0x0000
94
95#define THERMOSTAT_UPPER_LIMITS_TEMP 126.00
96#define THERMOSTAT_LOWER_LIMITS_TEMP -55.00
97#define THERMOSTAT_CALCULATE_COEF_MULT 1.8000
98#define THERMOSTAT_CALCULATE_COEF_PLUS 32.000 // End group macro
102// --------------------------------------------------------------- PUBLIC TYPES
111typedef struct
112{
113 // Output pins
114
115 digital_out_t rst;
116 digital_out_t te;
117
118 // Modules
119
120 i2c_master_t i2c;
121
122 // ctx variable
123
125
127
131typedef struct
132{
133 // Communication gpio pins
134
135 pin_name_t scl;
136 pin_name_t sda;
137
138 // Additional gpio pins
139
140 pin_name_t rst;
141 pin_name_t te;
142
143 // static variable
144
145 uint32_t i2c_speed;
146 uint8_t i2c_address;
147
149 // End types group
151
152// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
153
159#ifdef __cplusplus
160extern "C"{
161#endif
162
172
182
193void thermostat_generic_write ( thermostat_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
194
205void thermostat_generic_read ( thermostat_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
206
216void thermostat_write_data( thermostat_t *ctx, uint8_t reg_address, uint16_t write_data );
217
226 uint16_t thermostat_read_data( thermostat_t *ctx, uint8_t reg_address );
227
236
245float thermostat_convert_fahrenheit( thermostat_t *ctx, float temp_celsius );
246
255 void thermostat_set_configuration( thermostat_t *ctx, uint16_t config_value );
256
265 void thermostat_set_temp_hyst( thermostat_t *ctx, int8_t temp_hyst );
266
275void thermostat_set_temp_ref( thermostat_t *ctx, int8_t temp_ref );
276
285
294
303
312
321
322
323#ifdef __cplusplus
324}
325#endif
326#endif // _THERMOSTAT_H_
327 // End public_function group
330
331// ------------------------------------------------------------------------- END
#define THERMOSTAT_RETVAL
Definition: thermostat.h:64
void thermostat_soft_reset(thermostat_t *ctx)
Soft reset function.
void thermostat_switch_on(thermostat_t *ctx)
Set on thermal switch function.
void thermostat_generic_read(thermostat_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void thermostat_set_temp_hyst(thermostat_t *ctx, int8_t temp_hyst)
Set temperature hysterezis function.
float thermostat_get_temperature(thermostat_t *ctx)
Get temperature in degrees Celsius.
void thermostat_write_data(thermostat_t *ctx, uint8_t reg_address, uint16_t write_data)
Generic write 16-bit data function.
void thermostat_cfg_setup(thermostat_cfg_t *cfg)
Config Object Initialization function.
void thermostat_generic_write(thermostat_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint16_t thermostat_read_data(thermostat_t *ctx, uint8_t reg_address)
Generic read 16-bit data function.
void thermostat_enable(thermostat_t *ctx)
Thermostat enabled function.
void thermostat_disable(thermostat_t *ctx)
Thermostat disabled function.
void thermostat_switch_off(thermostat_t *ctx)
Set off thermal switch function.
float thermostat_convert_fahrenheit(thermostat_t *ctx, float temp_celsius)
Convert temperature in degrees Celsius to Fahrenheit.
void thermostat_set_temp_ref(thermostat_t *ctx, int8_t temp_ref)
Set referent temperature function.
void thermostat_set_configuration(thermostat_t *ctx, uint16_t config_value)
Set configuration function.
THERMOSTAT_RETVAL thermostat_init(thermostat_t *ctx, thermostat_cfg_t *cfg)
Initialization function.
Click configuration structure definition.
Definition: thermostat.h:132
uint32_t i2c_speed
Definition: thermostat.h:145
pin_name_t te
Definition: thermostat.h:141
pin_name_t scl
Definition: thermostat.h:135
pin_name_t sda
Definition: thermostat.h:136
pin_name_t rst
Definition: thermostat.h:140
uint8_t i2c_address
Definition: thermostat.h:146
Click ctx object definition.
Definition: thermostat.h:112
digital_out_t te
Definition: thermostat.h:116
i2c_master_t i2c
Definition: thermostat.h:120
digital_out_t rst
Definition: thermostat.h:115
uint8_t slave_address
Definition: thermostat.h:124