thermostat5  2.1.0.0
thermostat5.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 THERMOSTAT5_H
29 #define THERMOSTAT5_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_analog_in.h"
48 #include "drv_i2c_master.h"
49 
70 #define THERMOSTAT5_ROOM_TEMP_IN_K 293.15f
71 #define THERMOSTAT5_THERMISOR_BETA 3435.0f
72 #define THERMOSTAT5_INVERTED_VALUE 1.0f
73 #define THERMOSTAT5_TEMP_K_TO_C 273.15f
74 
79 #define THERMOSTAT5_RELAY_OFF 0
80 #define THERMOSTAT5_RELAY_ON 1
81 
86 #define THERMOSTAT5_ADC_RESOLUTION 0x0FFFu
87 #define THERMOSTAT5_VREF_3V3 3.3
88 #define THERMOSTAT5_VREF_5V 5.0
89 
95 #define THERMOSTAT5_SET_DEV_ADDR 0x4D
96  // thermostat5_set
98 
113 #define THERMOSTAT5_MAP_MIKROBUS( cfg, mikrobus ) \
114  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
115  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
116  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
117  cfg.on = MIKROBUS( mikrobus, MIKROBUS_PWM )
118  // thermostat5_map // thermostat5
121 
126 typedef enum
127 {
132 
137 typedef struct
138 {
139  digital_out_t on;
141  analog_in_t adc;
142  i2c_master_t i2c;
144  uint8_t slave_address;
145  float vref;
148 } thermostat5_t;
149 
154 typedef struct
155 {
156  pin_name_t an;
157  pin_name_t scl;
158  pin_name_t sda;
159  pin_name_t on;
161  analog_in_resolution_t resolution;
162  float vref;
164  uint32_t i2c_speed;
165  uint8_t i2c_address;
170 
175 typedef enum
176 {
178  THERMOSTAT5_ERROR = -1
179 
181 
198 
214 
229 
241 err_t thermostat5_read_raw_adc ( thermostat5_t *ctx, uint16_t *raw_adc );
242 
254 err_t thermostat5_read_voltage ( thermostat5_t *ctx, float *voltage );
255 
267 err_t thermostat5_set_vref ( thermostat5_t *ctx, float vref );
268 
280 err_t thermostat5_get_temperature ( thermostat5_t *ctx, float *temperature );
281 
293 void thermostat5_set_relay ( thermostat5_t *ctx, uint8_t state );
294 
295 #ifdef __cplusplus
296 }
297 #endif
298 #endif // THERMOSTAT5_H
299  // thermostat5
301 
302 // ------------------------------------------------------------------------ END
thermostat5_cfg_t::an
pin_name_t an
Definition: thermostat5.h:156
THERMOSTAT5_ERROR
@ THERMOSTAT5_ERROR
Definition: thermostat5.h:178
thermostat5_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: thermostat5.h:164
thermostat5_t::vref
float vref
Definition: thermostat5.h:145
thermostat5_cfg_t::on
pin_name_t on
Definition: thermostat5.h:159
THERMOSTAT5_OK
@ THERMOSTAT5_OK
Definition: thermostat5.h:177
thermostat5_t::on
digital_out_t on
Definition: thermostat5.h:139
thermostat5_drv_interface_sel
void thermostat5_drv_interface_sel(thermostat5_cfg_t *cfg, thermostat5_drv_t drv_sel)
Thermostat 5 driver interface setup function.
thermostat5_cfg_t::scl
pin_name_t scl
Definition: thermostat5.h:157
thermostat5_return_value_t
thermostat5_return_value_t
Thermostat 5 Click return value data.
Definition: thermostat5.h:176
thermostat5_cfg_t::sda
pin_name_t sda
Definition: thermostat5.h:158
thermostat5_read_voltage
err_t thermostat5_read_voltage(thermostat5_t *ctx, float *voltage)
Thermostat 5 read voltage level function.
THERMOSTAT5_DRV_SEL_ADC
@ THERMOSTAT5_DRV_SEL_ADC
Definition: thermostat5.h:128
thermostat5_cfg_t::resolution
analog_in_resolution_t resolution
Definition: thermostat5.h:161
thermostat5_init
err_t thermostat5_init(thermostat5_t *ctx, thermostat5_cfg_t *cfg)
Thermostat 5 initialization function.
thermostat5_t::drv_sel
thermostat5_drv_t drv_sel
Definition: thermostat5.h:146
thermostat5_drv_t
thermostat5_drv_t
Thermostat 5 Click driver selector.
Definition: thermostat5.h:127
thermostat5_cfg_t::i2c_address
uint8_t i2c_address
Definition: thermostat5.h:165
thermostat5_set_relay
void thermostat5_set_relay(thermostat5_t *ctx, uint8_t state)
Thermostat 5 set relay function.
thermostat5_cfg_setup
void thermostat5_cfg_setup(thermostat5_cfg_t *cfg)
Thermostat 5 configuration object setup function.
thermostat5_cfg_t::drv_sel
thermostat5_drv_t drv_sel
Definition: thermostat5.h:167
thermostat5_t::slave_address
uint8_t slave_address
Definition: thermostat5.h:144
thermostat5_read_raw_adc
err_t thermostat5_read_raw_adc(thermostat5_t *ctx, uint16_t *raw_adc)
Thermostat 5 read raw ADC value function.
thermostat5_t::adc
analog_in_t adc
Definition: thermostat5.h:141
thermostat5_set_vref
err_t thermostat5_set_vref(thermostat5_t *ctx, float vref)
Thermostat 5 set vref function.
thermostat5_t
Thermostat 5 Click context object.
Definition: thermostat5.h:138
thermostat5_get_temperature
err_t thermostat5_get_temperature(thermostat5_t *ctx, float *temperature)
Thermostat 5 get temperature function.
THERMOSTAT5_DRV_SEL_I2C
@ THERMOSTAT5_DRV_SEL_I2C
Definition: thermostat5.h:129
thermostat5_t::i2c
i2c_master_t i2c
Definition: thermostat5.h:142
thermostat5_cfg_t
Thermostat 5 Click configuration object.
Definition: thermostat5.h:155
thermostat5_cfg_t::vref
float vref
Definition: thermostat5.h:162