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
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_one_wire.h"
52
73#define THERMOSTAT2_CMD_WRITE_SCRATCHPAD 0x4E
74#define THERMOSTAT2_CMD_READ_SCRATCHPAD 0xBE
75#define THERMOSTAT2_CMD_COPY_SCRATCHPAD 0x48
76#define THERMOSTAT2_CMD_CONVERT_TEMPERATURE 0x44
77#define THERMOSTAT2_CMD_RECALL_SCRATCHPAD 0xB8
78#define THERMOSTAT2_CMD_READ_POWER_SUPPLY 0xB4
79
80 // thermostat2_cmd
81
96#define THERMOSTAT2_CONFIG_RESOLUTION_9BIT 0x00
97#define THERMOSTAT2_CONFIG_RESOLUTION_10BIT 0x20
98#define THERMOSTAT2_CONFIG_RESOLUTION_11BIT 0x40
99#define THERMOSTAT2_CONFIG_RESOLUTION_12BIT 0x60
100#define THERMOSTAT2_CONFIG_RESOLUTION_BIT_MASK 0x60
101#define THERMOSTAT2_CONFIG_RESERVED_BITS 0x1F
102
107#define THERMOSTAT2_FAMILY_CODE 0x10
108
113#define THERMOSTAT2_RESOLUTION_9BIT 0.5
114#define THERMOSTAT2_RESOLUTION_10BIT 0.25
115#define THERMOSTAT2_RESOLUTION_11BIT 0.125
116#define THERMOSTAT2_RESOLUTION_12BIT 0.0625
117
122#define THERMOSTAT2_DEFAULT_RESOLUTION THERMOSTAT2_CONFIG_RESOLUTION_9BIT
123#define THERMOSTAT2_DEFAULT_TEMP_HIGH_ALARM 0xFF
124#define THERMOSTAT2_DEFAULT_TEMP_LOW_ALARM 0x00
125
130#define THERMOSTAT2_RELAY_ON 0x01
131#define THERMOSTAT2_RELAY_OFF 0x00
132#define THERMOSTAT2_TEMPERATURE_LIMIT 28.0
133
134 // thermostat2_set
135
150#define THERMOSTAT2_MAP_MIKROBUS( cfg, mikrobus ) \
151 cfg.gp0 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
152 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
153
154 // thermostat2_map
155 // thermostat2
156
161typedef struct
162{
163 digital_out_t cs;
165 // Modules
166 one_wire_t ow;
168 one_wire_rom_address_t rom_addr;
169 uint8_t config;
172
177typedef struct
178{
179 // Communication gpio pins
180 pin_name_t gp0;
181 pin_name_t cs;
184
195
212
228
243
256
268err_t thermostat2_read_scratchpad ( thermostat2_t *ctx, uint8_t *scratchpad );
269
283err_t thermostat2_write_scratchpad ( thermostat2_t *ctx, uint8_t temp_high, uint8_t temp_low, uint8_t config );
284
296
306void thermostat2_relay_state ( thermostat2_t *ctx, uint8_t state );
307
319err_t thermostat2_read_temperature ( thermostat2_t *ctx, float *temperature );
320
321#ifdef __cplusplus
322}
323#endif
324#endif // THERMOSTAT2_H
325
326 // thermostat2
327
328// ------------------------------------------------------------------------ END
err_t thermostat2_read_temperature(thermostat2_t *ctx, float *temperature)
Thermostat 2 read temperature function.
err_t thermostat2_start_measurement(thermostat2_t *ctx)
Thermostat 2 start measurement function.
err_t thermostat2_write_scratchpad(thermostat2_t *ctx, uint8_t temp_high, uint8_t temp_low, uint8_t config)
Thermostat 2 write scratchpad function.
void thermostat2_cfg_setup(thermostat2_cfg_t *cfg)
Thermostat 2 configuration object setup function.
void thermostat2_relay_state(thermostat2_t *ctx, uint8_t state)
Thermostat 2 relay state function.
err_t thermostat2_read_scratchpad(thermostat2_t *ctx, uint8_t *scratchpad)
Thermostat 2 read scratchpad function.
err_t thermostat2_check_communication(thermostat2_t *ctx)
Thermostat 2 check communication function.
err_t thermostat2_init(thermostat2_t *ctx, thermostat2_cfg_t *cfg)
Thermostat 2 initialization function.
err_t thermostat2_default_cfg(thermostat2_t *ctx)
Thermostat 2 default configuration function.
Thermostat 2 Click configuration object.
Definition thermostat2.h:178
pin_name_t gp0
Definition thermostat2.h:180
pin_name_t cs
Definition thermostat2.h:181
Thermostat 2 Click context object.
Definition thermostat2.h:162
digital_out_t cs
Definition thermostat2.h:163
one_wire_rom_address_t rom_addr
Definition thermostat2.h:168
uint8_t config
Definition thermostat2.h:169
one_wire_t ow
Definition thermostat2.h:166
thermostat2_return_value_t
Thermostat 2 Click return value data.
Definition thermostat2.h:190
@ THERMOSTAT2_OK
Definition thermostat2.h:191
@ THERMOSTAT2_ERROR
Definition thermostat2.h:192