thermostat4  2.0.0.0
thermostat4.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef THERMOSTAT4_H
29 #define THERMOSTAT4_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 
59 #define THERMOSTAT4_RELAY_ON 0x01
60 #define THERMOSTAT4_RELAY_OFF 0x00
61 
62 #define THERMOSTAT4_RESET_ON 0x01
63 #define THERMOSTAT4_RESET_OFF 0x00
64 
65 #define THERMOSTAT4_WARM_ALERT 0x00
66 #define THERMOSTAT4_HOT_ALERT 0x00
67 
76 #define THERMOSTAT4_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
77 #define THERMOSTAT4_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
78  // thermostat4_set
80 
95 #define THERMOSTAT4_MAP_MIKROBUS( cfg, mikrobus ) \
96  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
97  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
98  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
99  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
100  cfg.oa = MIKROBUS( mikrobus, MIKROBUS_AN ); \
101  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
102  cfg.rly = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
103  cfg.ob = MIKROBUS( mikrobus, MIKROBUS_INT )
104  // thermostat4_map // thermostat4
107 
112 typedef struct
113 {
114  // Output pins
115  digital_out_t rst;
116  digital_out_t rly;
117  digital_out_t cs;
119  // Input pins
120  digital_in_t oa;
121  digital_in_t ob;
123  // Modules
124  spi_master_t spi;
126  pin_name_t chip_select;
128 } thermostat4_t;
129 
134 typedef struct
135 {
136  // Communication gpio pins
137  pin_name_t miso;
138  pin_name_t mosi;
139  pin_name_t sck;
140  pin_name_t cs;
142  // Additional gpio pins
143  pin_name_t oa;
144  pin_name_t rst;
145  pin_name_t rly;
146  pin_name_t ob;
148  // static variable
149  uint32_t spi_speed;
150  spi_master_mode_t spi_mode;
151  spi_master_chip_select_polarity_t cs_polarity;
154 
159 typedef enum
160 {
162  THERMOSTAT4_ERROR = -1
163 
165 
182 
197 
209 void thermostat4_generic_transfer ( thermostat4_t *ctx, uint8_t *data_in, uint16_t wr_len,
210  uint8_t *data_out, uint16_t rd_len );
211 
220 void thermostat4_relay_ctrl ( thermostat4_t *ctx, uint8_t state );
221 
230 void thermostat4_rst_pin_ctrl ( thermostat4_t *ctx, uint8_t state );
231 
240 
249 
258 void thermostat4_set_warm_hysteresis ( thermostat4_t *ctx, uint8_t hyst_data );
259 
268 
269 #ifdef __cplusplus
270 }
271 #endif
272 #endif // _THERMOSTAT4_H_
273  // thermostat 4
275 // ------------------------------------------------------------------------- END
thermostat4_new_cfg_upload
void thermostat4_new_cfg_upload(thermostat4_t *ctx)
Reset module and upload new configuration on the Warm channel.
thermostat4_hot_alert_state
uint8_t thermostat4_hot_alert_state(thermostat4_t *ctx)
Hot temperature ALERT.
thermostat4_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: thermostat4.h:150
thermostat4_t::cs
digital_out_t cs
Definition: thermostat4.h:117
thermostat4_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: thermostat4.h:151
thermostat4_cfg_t
Thermostat 4 Click configuration object.
Definition: thermostat4.h:135
thermostat4_relay_ctrl
void thermostat4_relay_ctrl(thermostat4_t *ctx, uint8_t state)
Relay Control.
thermostat4_cfg_t::rst
pin_name_t rst
Definition: thermostat4.h:144
thermostat4_cfg_setup
void thermostat4_cfg_setup(thermostat4_cfg_t *cfg)
Thermostat 4 configuration object setup function.
thermostat4_t::rly
digital_out_t rly
Definition: thermostat4.h:116
thermostat4_cfg_t::spi_speed
uint32_t spi_speed
Definition: thermostat4.h:149
thermostat4_rst_pin_ctrl
void thermostat4_rst_pin_ctrl(thermostat4_t *ctx, uint8_t state)
Sets reset pin state.
THERMOSTAT4_ERROR
@ THERMOSTAT4_ERROR
Definition: thermostat4.h:162
thermostat4_cfg_t::miso
pin_name_t miso
Definition: thermostat4.h:137
thermostat4_t::chip_select
pin_name_t chip_select
Definition: thermostat4.h:126
thermostat4_t::spi
spi_master_t spi
Definition: thermostat4.h:124
thermostat4_cfg_t::cs
pin_name_t cs
Definition: thermostat4.h:140
thermostat4_cfg_t::oa
pin_name_t oa
Definition: thermostat4.h:143
thermostat4_return_value_t
thermostat4_return_value_t
Thermostat 4 Click return value data.
Definition: thermostat4.h:160
THERMOSTAT4_OK
@ THERMOSTAT4_OK
Definition: thermostat4.h:161
thermostat4_warm_alert_state
uint8_t thermostat4_warm_alert_state(thermostat4_t *ctx)
Warm temperature ALERT.
thermostat4_t::ob
digital_in_t ob
Definition: thermostat4.h:121
thermostat4_t::rst
digital_out_t rst
Definition: thermostat4.h:115
thermostat4_t::oa
digital_in_t oa
Definition: thermostat4.h:120
thermostat4_cfg_t::sck
pin_name_t sck
Definition: thermostat4.h:139
thermostat4_cfg_t::rly
pin_name_t rly
Definition: thermostat4.h:145
thermostat4_t
Thermostat 4 Click context object.
Definition: thermostat4.h:113
thermostat4_cfg_t::ob
pin_name_t ob
Definition: thermostat4.h:146
thermostat4_init
err_t thermostat4_init(thermostat4_t *ctx, thermostat4_cfg_t *cfg)
Thermostat 4 initialization function.
thermostat4_set_warm_hysteresis
void thermostat4_set_warm_hysteresis(thermostat4_t *ctx, uint8_t hyst_data)
Hysteresis on the Warm channel.
thermostat4_generic_transfer
void thermostat4_generic_transfer(thermostat4_t *ctx, uint8_t *data_in, uint16_t wr_len, uint8_t *data_out, uint16_t rd_len)
Generic transfer function.
thermostat4_cfg_t::mosi
pin_name_t mosi
Definition: thermostat4.h:138