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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
54 #define THERMOSTAT3_MAP_MIKROBUS( cfg, mikrobus ) \
55  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
56  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
57  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
58  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
59  cfg.rly = MIKROBUS( mikrobus, MIKROBUS_PWM)
60 
66 #define THERMOSTAT_RETVAL uint8_t
67 
68 #define THERMOSTAT_OK 0x00
69 #define THERMOSTAT_INIT_ERROR 0xFF
70 
76 #define THERMOSTAT3_RELAY_ON 0x01
77 #define THERMOSTAT3_RELAY_OFF 0x00
78 
84 #define THERMOSTAT3_TEMP_IN_CELSIUS 0x00
85 #define THERMOSTAT3_TEMP_IN_FAHRENHEIT 0x02
86 #define THERMOSTAT3_TEMP_IN_KELVIN 0x01
87 
93 #define THERMOSTAT3_FAULT_ACTIVE_FLAG 0x08
94 #define THERMOSTAT3_FAULT_SCV_FLAG 0x04
95 #define THERMOSTAT3_FAULT_SCG_FLAG 0x02
96 #define THERMOSTAT3_FAULT_OC_FLAG 0x01
97 #define THERMOSTAT3_FAULT_ALL_FLAG 0x00
98 
104 #define NULL 0x00
105  // End group macro
108 // --------------------------------------------------------------- PUBLIC TYPES
117 typedef struct
118 {
119  // Output pins
120 
121  digital_out_t rly;
122  digital_out_t cs;
123 
124  // Modules
125 
126  spi_master_t spi;
127  pin_name_t chip_select;
128 
129  uint8_t relay_flag;
130  uint8_t fault_flag;
131  uint8_t f_error;
132  uint8_t fault_status;
133 
134 } thermostat3_t;
135 
139 typedef struct
140 {
141  // Communication gpio pins
142 
143  pin_name_t miso;
144  pin_name_t mosi;
145  pin_name_t sck;
146  pin_name_t cs;
147 
148  // Additional gpio pins
149 
150  pin_name_t rly;
151 
152  // static variable
153 
154  uint32_t spi_speed;
155  uint8_t spi_mode;
156  spi_master_chip_select_polarity_t cs_polarity;
157 
161 
163 
164 typedef struct
165 {
168  uint8_t fault_value;
169 
170 } temp_vals_t;
171 
172  // End types group
174 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
175 
180 #ifdef __cplusplus
181 extern "C"{
182 #endif
183 
193 
202 
203 void thermostat3_generic_read ( thermostat3_t *ctx, uint8_t *read_buff );
204 
214 void thermostat3_process ( thermostat3_t *ctx, temp_vals_t *tmp );
215 
226 float thermostat3_get_internal_temperature ( temp_vals_t *tmp, uint8_t temp_in );
227 
238 float thermostat3_get_thermocouple_temperature ( temp_vals_t *tmp, uint8_t temp_in );
239 
250 uint8_t thermostat3_get_fault_data ( temp_vals_t *tmp, uint8_t err );
251 
260 void thermostat3_relay_control ( thermostat3_t *ctx, uint8_t relay_pos );
261 
262 #ifdef __cplusplus
263 }
264 #endif
265 #endif // _THERMOSTAT_H_
266  // End public_function group
269 
270 // ------------------------------------------------------------------------- END
pin_name_t cs
Definition: thermostat3.h:146
float thermocouple_temp
Definition: thermostat3.h:167
float thermostat3_get_thermocouple_temperature(temp_vals_t *tmp, uint8_t temp_in)
Thermocouple Temperature (K probe)
digital_out_t cs
Definition: thermostat3.h:122
void thermostat3_relay_control(thermostat3_t *ctx, uint8_t relay_pos)
Relay Control.
float internal_temp
Definition: thermostat3.h:166
float thermostat3_get_internal_temperature(temp_vals_t *tmp, uint8_t temp_in)
Junction (Internal) Temperature.
uint8_t fault_flag
Definition: thermostat3.h:130
pin_name_t rly
Definition: thermostat3.h:150
uint8_t fault_value
Definition: thermostat3.h:168
uint32_t spi_speed
Definition: thermostat3.h:154
THERMOSTAT_RETVAL thermostat3_init(thermostat3_t *ctx, thermostat3_cfg_t *cfg)
Initialization function.
uint8_t fault_status
Definition: thermostat3.h:132
pin_name_t sck
Definition: thermostat3.h:145
spi_master_t spi
Definition: thermostat3.h:126
#define THERMOSTAT_RETVAL
Definition: thermostat3.h:66
uint8_t fault_value_cfg
Definition: thermostat3.h:160
uint8_t f_error
Definition: thermostat3.h:131
void thermostat3_cfg_setup(thermostat3_cfg_t *cfg)
Config Object Initialization function.
Click ctx object definition.
Definition: thermostat3.h:117
void thermostat3_generic_read(thermostat3_t *ctx, uint8_t *read_buff)
float thermocouple_temp_cfg
Definition: thermostat3.h:159
Click configuration structure definition.
Definition: thermostat3.h:139
uint8_t spi_mode
Definition: thermostat3.h:155
pin_name_t mosi
Definition: thermostat3.h:144
void thermostat3_process(thermostat3_t *ctx, temp_vals_t *tmp)
Thermostat Process Read data.
pin_name_t miso
Definition: thermostat3.h:143
uint8_t relay_flag
Definition: thermostat3.h:129
digital_out_t rly
Definition: thermostat3.h:121
float internal_temp_cfg
Definition: thermostat3.h:158
spi_master_chip_select_polarity_t cs_polarity
Definition: thermostat3.h:156
Definition: thermostat3.h:164
uint8_t thermostat3_get_fault_data(temp_vals_t *tmp, uint8_t err)
Fault data value.
pin_name_t chip_select
Definition: thermostat3.h:127