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 "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_spi_master.h"
51 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
64 #define THERMOSTAT3_MAP_MIKROBUS( cfg, mikrobus ) \
65  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
66  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
67  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
68  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
69  cfg.rly = MIKROBUS( mikrobus, MIKROBUS_PWM)
70 
76 #define THERMOSTAT_RETVAL uint8_t
77 
78 #define THERMOSTAT_OK 0x00
79 #define THERMOSTAT_INIT_ERROR 0xFF
80 
86 #define THERMOSTAT3_RELAY_ON 0x01
87 #define THERMOSTAT3_RELAY_OFF 0x00
88 
94 #define THERMOSTAT3_TEMP_IN_CELSIUS 0x00
95 #define THERMOSTAT3_TEMP_IN_FAHRENHEIT 0x02
96 #define THERMOSTAT3_TEMP_IN_KELVIN 0x01
97 
103 #define THERMOSTAT3_FAULT_ACTIVE_FLAG 0x08
104 #define THERMOSTAT3_FAULT_SCV_FLAG 0x04
105 #define THERMOSTAT3_FAULT_SCG_FLAG 0x02
106 #define THERMOSTAT3_FAULT_OC_FLAG 0x01
107 #define THERMOSTAT3_FAULT_ALL_FLAG 0x00
108 
114 #define NULL 0x00
115  // End group macro
118 // --------------------------------------------------------------- PUBLIC TYPES
127 typedef struct
128 {
129  // Output pins
130 
131  digital_out_t rly;
132  digital_out_t cs;
133 
134  // Modules
135 
136  spi_master_t spi;
137  pin_name_t chip_select;
138 
139  uint8_t relay_flag;
140  uint8_t fault_flag;
141  uint8_t f_error;
142  uint8_t fault_status;
143 
144 } thermostat3_t;
145 
149 typedef struct
150 {
151  // Communication gpio pins
152 
153  pin_name_t miso;
154  pin_name_t mosi;
155  pin_name_t sck;
156  pin_name_t cs;
157 
158  // Additional gpio pins
159 
160  pin_name_t rly;
161 
162  // static variable
163 
164  uint32_t spi_speed;
165  uint8_t spi_mode;
166  spi_master_chip_select_polarity_t cs_polarity;
167 
171 
173 
174 typedef struct
175 {
178  uint8_t fault_value;
179 
180 } temp_vals_t;
181 
182  // End types group
184 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
185 
190 #ifdef __cplusplus
191 extern "C"{
192 #endif
193 
203 
212 
213 void thermostat3_generic_read ( thermostat3_t *ctx, uint8_t *read_buff );
214 
225 
236 float thermostat3_get_internal_temperature ( temp_vals_t *tmp, uint8_t temp_in );
237 
249 
260 uint8_t thermostat3_get_fault_data ( temp_vals_t *tmp, uint8_t err );
261 
270 void thermostat3_relay_control ( thermostat3_t *ctx, uint8_t relay_pos );
271 
272 #ifdef __cplusplus
273 }
274 #endif
275 #endif // _THERMOSTAT_H_
276  // End public_function group
279 
280 // ------------------------------------------------------------------------- END
thermostat3_cfg_t::cs
pin_name_t cs
Definition: thermostat3.h:156
thermostat3_t::chip_select
pin_name_t chip_select
Definition: thermostat3.h:137
thermostat3_t::fault_flag
uint8_t fault_flag
Definition: thermostat3.h:140
thermostat3_process
void thermostat3_process(thermostat3_t *ctx, temp_vals_t *tmp)
Thermostat Process Read data.
THERMOSTAT_RETVAL
#define THERMOSTAT_RETVAL
Definition: thermostat3.h:76
thermostat3_cfg_t
Click configuration structure definition.
Definition: thermostat3.h:150
thermostat3_cfg_t::fault_value_cfg
uint8_t fault_value_cfg
Definition: thermostat3.h:170
temp_vals_t::internal_temp
float internal_temp
Definition: thermostat3.h:176
temp_vals_t::thermocouple_temp
float thermocouple_temp
Definition: thermostat3.h:177
thermostat3_t::fault_status
uint8_t fault_status
Definition: thermostat3.h:142
thermostat3_relay_control
void thermostat3_relay_control(thermostat3_t *ctx, uint8_t relay_pos)
Relay Control.
thermostat3_cfg_setup
void thermostat3_cfg_setup(thermostat3_cfg_t *cfg)
Config Object Initialization function.
thermostat3_t::f_error
uint8_t f_error
Definition: thermostat3.h:141
thermostat3_cfg_t::rly
pin_name_t rly
Definition: thermostat3.h:160
temp_vals_t::fault_value
uint8_t fault_value
Definition: thermostat3.h:178
thermostat3_t::relay_flag
uint8_t relay_flag
Definition: thermostat3.h:139
thermostat3_cfg_t::miso
pin_name_t miso
Definition: thermostat3.h:153
thermostat3_t::cs
digital_out_t cs
Definition: thermostat3.h:132
thermostat3_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: thermostat3.h:166
thermostat3_t::spi
spi_master_t spi
Definition: thermostat3.h:136
thermostat3_generic_read
void thermostat3_generic_read(thermostat3_t *ctx, uint8_t *read_buff)
thermostat3_get_fault_data
uint8_t thermostat3_get_fault_data(temp_vals_t *tmp, uint8_t err)
Fault data value.
thermostat3_cfg_t::spi_mode
uint8_t spi_mode
Definition: thermostat3.h:165
thermostat3_cfg_t::mosi
pin_name_t mosi
Definition: thermostat3.h:154
thermostat3_init
THERMOSTAT_RETVAL thermostat3_init(thermostat3_t *ctx, thermostat3_cfg_t *cfg)
Initialization function.
thermostat3_get_thermocouple_temperature
float thermostat3_get_thermocouple_temperature(temp_vals_t *tmp, uint8_t temp_in)
Thermocouple Temperature (K probe)
thermostat3_t
Click ctx object definition.
Definition: thermostat3.h:128
thermostat3_cfg_t::thermocouple_temp_cfg
float thermocouple_temp_cfg
Definition: thermostat3.h:169
thermostat3_t::rly
digital_out_t rly
Definition: thermostat3.h:131
thermostat3_cfg_t::internal_temp_cfg
float internal_temp_cfg
Definition: thermostat3.h:168
thermostat3_cfg_t::spi_speed
uint32_t spi_speed
Definition: thermostat3.h:164
thermostat3_cfg_t::sck
pin_name_t sck
Definition: thermostat3.h:155
temp_vals_t
Definition: thermostat3.h:175
thermostat3_get_internal_temperature
float thermostat3_get_internal_temperature(temp_vals_t *tmp, uint8_t temp_in)
Junction (Internal) Temperature.