thermostat3 2.0.0.0
thermostat3.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
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_spi_master.h"
55
56
57// -------------------------------------------------------------- PUBLIC MACROS
68#define THERMOSTAT3_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
70 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
71 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
72 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73 cfg.rly = MIKROBUS( mikrobus, MIKROBUS_PWM)
80#define THERMOSTAT_RETVAL uint8_t
81
82#define THERMOSTAT_OK 0x00
83#define THERMOSTAT_INIT_ERROR 0xFF
90#define THERMOSTAT3_RELAY_ON 0x01
91#define THERMOSTAT3_RELAY_OFF 0x00
98#define THERMOSTAT3_TEMP_IN_CELSIUS 0x00
99#define THERMOSTAT3_TEMP_IN_FAHRENHEIT 0x02
100#define THERMOSTAT3_TEMP_IN_KELVIN 0x01
107#define THERMOSTAT3_FAULT_ACTIVE_FLAG 0x08
108#define THERMOSTAT3_FAULT_SCV_FLAG 0x04
109#define THERMOSTAT3_FAULT_SCG_FLAG 0x02
110#define THERMOSTAT3_FAULT_OC_FLAG 0x01
111#define THERMOSTAT3_FAULT_ALL_FLAG 0x00
118#define NULL 0x00
121 // End group macro
122// --------------------------------------------------------------- PUBLIC TYPES
131typedef struct
132{
133 // Output pins
134
135 digital_out_t rly;
136 digital_out_t cs;
137
138 // Modules
139
140 spi_master_t spi;
141 pin_name_t chip_select;
142
143 uint8_t relay_flag;
144 uint8_t fault_flag;
145 uint8_t f_error;
147
149
153typedef struct
154{
155 // Communication gpio pins
156
157 pin_name_t miso;
158 pin_name_t mosi;
159 pin_name_t sck;
160 pin_name_t cs;
161
162 // Additional gpio pins
163
164 pin_name_t rly;
165
166 // static variable
167
168 uint32_t spi_speed;
169 uint8_t spi_mode;
170 spi_master_chip_select_polarity_t cs_polarity;
171
175
177
178typedef struct
179{
182 uint8_t fault_value;
183
185
186
187 // End types group
188// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
189
194#ifdef __cplusplus
195extern "C"{
196#endif
197
207
216
217void thermostat3_generic_read ( thermostat3_t *ctx, uint8_t *read_buff );
218
229
240float thermostat3_get_internal_temperature ( temp_vals_t *tmp, uint8_t temp_in );
241
253
264uint8_t thermostat3_get_fault_data ( temp_vals_t *tmp, uint8_t err );
265
274void thermostat3_relay_control ( thermostat3_t *ctx, uint8_t relay_pos );
275
276#ifdef __cplusplus
277}
278#endif
279#endif // _THERMOSTAT_H_
280
281 // End public_function group
283
284// ------------------------------------------------------------------------- END
#define THERMOSTAT_RETVAL
Definition thermostat3.h:80
uint8_t thermostat3_get_fault_data(temp_vals_t *tmp, uint8_t err)
Fault data value.
void thermostat3_relay_control(thermostat3_t *ctx, uint8_t relay_pos)
Relay Control.
float thermostat3_get_internal_temperature(temp_vals_t *tmp, uint8_t temp_in)
Junction (Internal) Temperature.
THERMOSTAT_RETVAL thermostat3_init(thermostat3_t *ctx, thermostat3_cfg_t *cfg)
Initialization function.
void thermostat3_generic_read(thermostat3_t *ctx, uint8_t *read_buff)
void thermostat3_process(thermostat3_t *ctx, temp_vals_t *tmp)
Thermostat Process Read data.
float thermostat3_get_thermocouple_temperature(temp_vals_t *tmp, uint8_t temp_in)
Thermocouple Temperature (K probe)
void thermostat3_cfg_setup(thermostat3_cfg_t *cfg)
Config Object Initialization function.
Definition thermostat3.h:179
uint8_t fault_value
Definition thermostat3.h:182
float thermocouple_temp
Definition thermostat3.h:181
float internal_temp
Definition thermostat3.h:180
Click configuration structure definition.
Definition thermostat3.h:154
uint8_t spi_mode
Definition thermostat3.h:169
float thermocouple_temp_cfg
Definition thermostat3.h:173
float internal_temp_cfg
Definition thermostat3.h:172
uint8_t fault_value_cfg
Definition thermostat3.h:174
pin_name_t rly
Definition thermostat3.h:164
spi_master_chip_select_polarity_t cs_polarity
Definition thermostat3.h:170
pin_name_t sck
Definition thermostat3.h:159
pin_name_t mosi
Definition thermostat3.h:158
uint32_t spi_speed
Definition thermostat3.h:168
pin_name_t miso
Definition thermostat3.h:157
pin_name_t cs
Definition thermostat3.h:160
Click ctx object definition.
Definition thermostat3.h:132
digital_out_t cs
Definition thermostat3.h:136
uint8_t relay_flag
Definition thermostat3.h:143
spi_master_t spi
Definition thermostat3.h:140
uint8_t fault_flag
Definition thermostat3.h:144
digital_out_t rly
Definition thermostat3.h:135
uint8_t f_error
Definition thermostat3.h:145
uint8_t fault_status
Definition thermostat3.h:146
pin_name_t chip_select
Definition thermostat3.h:141