thermostat2  2.0.0.0
thermostat2.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 THERMOSTAT2_H
29 #define THERMOSTAT2_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_one_wire.h"
48 
69 #define THERMOSTAT2_CMD_WRITE_SCRATCHPAD 0x4E
70 #define THERMOSTAT2_CMD_READ_SCRATCHPAD 0xBE
71 #define THERMOSTAT2_CMD_COPY_SCRATCHPAD 0x48
72 #define THERMOSTAT2_CMD_CONVERT_TEMPERATURE 0x44
73 #define THERMOSTAT2_CMD_RECALL_SCRATCHPAD 0xB8
74 #define THERMOSTAT2_CMD_READ_POWER_SUPPLY 0xB4
75  // thermostat2_cmd
77 
92 #define THERMOSTAT2_CONFIG_RESOLUTION_9BIT 0x00
93 #define THERMOSTAT2_CONFIG_RESOLUTION_10BIT 0x20
94 #define THERMOSTAT2_CONFIG_RESOLUTION_11BIT 0x40
95 #define THERMOSTAT2_CONFIG_RESOLUTION_12BIT 0x60
96 #define THERMOSTAT2_CONFIG_RESOLUTION_BIT_MASK 0x60
97 #define THERMOSTAT2_CONFIG_RESERVED_BITS 0x1F
98 
103 #define THERMOSTAT2_FAMILY_CODE 0x10
104 
109 #define THERMOSTAT2_RESOLUTION_9BIT 0.5
110 #define THERMOSTAT2_RESOLUTION_10BIT 0.25
111 #define THERMOSTAT2_RESOLUTION_11BIT 0.125
112 #define THERMOSTAT2_RESOLUTION_12BIT 0.0625
113 
118 #define THERMOSTAT2_DEFAULT_RESOLUTION THERMOSTAT2_CONFIG_RESOLUTION_9BIT
119 #define THERMOSTAT2_DEFAULT_TEMP_HIGH_ALARM 0xFF
120 #define THERMOSTAT2_DEFAULT_TEMP_LOW_ALARM 0x00
121 
126 #define THERMOSTAT2_RELAY_ON 0x01
127 #define THERMOSTAT2_RELAY_OFF 0x00
128 #define THERMOSTAT2_TEMPERATURE_LIMIT 28.0
129  // thermostat2_set
131 
146 #define THERMOSTAT2_MAP_MIKROBUS( cfg, mikrobus ) \
147  cfg.gp0 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
148  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
149  // thermostat2_map // thermostat2
152 
157 typedef struct
158 {
159  digital_out_t cs;
161  // Modules
162  one_wire_t ow;
164  one_wire_rom_address_t rom_addr;
165  uint8_t config;
167 } thermostat2_t;
168 
173 typedef struct
174 {
175  // Communication gpio pins
176  pin_name_t gp0;
177  pin_name_t cs;
180 
185 typedef enum
186 {
188  THERMOSTAT2_ERROR = -1
189 
191 
208 
224 
239 
252 
264 err_t thermostat2_read_scratchpad ( thermostat2_t *ctx, uint8_t *scratchpad );
265 
279 err_t thermostat2_write_scratchpad ( thermostat2_t *ctx, uint8_t temp_high, uint8_t temp_low, uint8_t config );
280 
292 
302 void thermostat2_relay_state ( thermostat2_t *ctx, uint8_t state );
303 
315 err_t thermostat2_read_temperature ( thermostat2_t *ctx, float *temperature );
316 
317 #ifdef __cplusplus
318 }
319 #endif
320 #endif // THERMOSTAT2_H
321  // thermostat2
323 
324 // ------------------------------------------------------------------------ END
thermostat2_t::rom_addr
one_wire_rom_address_t rom_addr
Definition: thermostat2.h:164
thermostat2_t::cs
digital_out_t cs
Definition: thermostat2.h:159
thermostat2_t::config
uint8_t config
Definition: thermostat2.h:165
thermostat2_cfg_t
Thermostat 2 Click configuration object.
Definition: thermostat2.h:174
THERMOSTAT2_OK
@ THERMOSTAT2_OK
Definition: thermostat2.h:187
thermostat2_read_temperature
err_t thermostat2_read_temperature(thermostat2_t *ctx, float *temperature)
Thermostat 2 read temperature function.
thermostat2_default_cfg
err_t thermostat2_default_cfg(thermostat2_t *ctx)
Thermostat 2 default configuration function.
thermostat2_check_communication
err_t thermostat2_check_communication(thermostat2_t *ctx)
Thermostat 2 check communication function.
thermostat2_relay_state
void thermostat2_relay_state(thermostat2_t *ctx, uint8_t state)
Thermostat 2 relay state function.
thermostat2_cfg_t::gp0
pin_name_t gp0
Definition: thermostat2.h:176
THERMOSTAT2_ERROR
@ THERMOSTAT2_ERROR
Definition: thermostat2.h:188
thermostat2_t::ow
one_wire_t ow
Definition: thermostat2.h:162
thermostat2_return_value_t
thermostat2_return_value_t
Thermostat 2 Click return value data.
Definition: thermostat2.h:186
thermostat2_init
err_t thermostat2_init(thermostat2_t *ctx, thermostat2_cfg_t *cfg)
Thermostat 2 initialization function.
thermostat2_start_measurement
err_t thermostat2_start_measurement(thermostat2_t *ctx)
Thermostat 2 start measurement function.
thermostat2_write_scratchpad
err_t thermostat2_write_scratchpad(thermostat2_t *ctx, uint8_t temp_high, uint8_t temp_low, uint8_t config)
Thermostat 2 write scratchpad function.
thermostat2_cfg_t::cs
pin_name_t cs
Definition: thermostat2.h:177
thermostat2_cfg_setup
void thermostat2_cfg_setup(thermostat2_cfg_t *cfg)
Thermostat 2 configuration object setup function.
thermostat2_read_scratchpad
err_t thermostat2_read_scratchpad(thermostat2_t *ctx, uint8_t *scratchpad)
Thermostat 2 read scratchpad function.
thermostat2_t
Thermostat 2 Click context object.
Definition: thermostat2.h:158