heater  2.0.0.0
heater.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 HEATER_H
36 #define HEATER_H
37 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_i2c_master.h"
55 #include "drv_pwm.h"
56 
57 
58 // -------------------------------------------------------------- PUBLIC MACROS
68 #define HEATER_MAP_MIKROBUS( cfg, mikrobus ) \
69  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
70  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
71  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
72  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73  cfg1.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
74 
81 #define HEATER_RETVAL uint8_t
82 
83 #define HEATER_OK 0x00
84 #define HEATER_INIT_ERROR 0xFF
85 
91 #define HEATER_SLAVE_ADDRESS 0x4D
92 
98 #define HEATER_LED_ON 1
99 #define HEATER_LED_OFF 0
100 
105 #define HEATER_SHIFT_DATA 8
106 #define HEATER_ADC_VREF 3300.00f
107 #define HEATER_MV_RESOLUTION 4096.00f
108 #define HEATER_TEMP_RESOLUTION 10.0f
109 #define HEATER_TEMP_0 500.0
110 
112 #define HEATER_DEF_FREQ 500
113  // End group macro
115 // --------------------------------------------------------------- PUBLIC TYPES
124 typedef struct
125 {
126  // Output pins
127 
128  digital_out_t rst;
129  digital_out_t cs;
130 
131  // Modules
132 
133  i2c_master_t i2c;
134  pwm_t pwm;
135 
136  // ctx variable
137 
138  uint8_t slave_address;
139  uint32_t pwm_freq;
140 
141 } heater_t;
142 
146 typedef struct
147 {
148  // Communication gpio pins
149 
150  pin_name_t scl;
151  pin_name_t sda;
152 
153 
154  // Additional gpio pins
155 
156  pin_name_t rst;
157  pin_name_t cs;
158 
159  // static variable
160 
161  uint32_t i2c_speed;
162  uint8_t i2c_address;
163 
164 } heater_cfg_t;
165 
166 typedef struct
167 {
168  pin_name_t pwm;
169 
170  uint32_t dev_pwm_freq;
171 
173  // End types group
175 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
176 
182 #ifdef __cplusplus
183 extern "C"{
184 #endif
185 
195 
205 
213 void heater_set_led1_status ( heater_t *ctx, uint8_t status );
214 
222 void heater_set_led2_status ( heater_t *ctx, uint8_t status );
223 
231 uint16_t heater_read_data ( heater_t *ctx );
232 
240 float heater_read_mv ( heater_t *ctx );
241 
249 float heater_read_temp ( heater_t *ctx );
250 
260 void heater_set_duty_cycle ( heater_t *ctx, float duty_cycle );
261 
269 void heater_pwm_stop ( heater_t *ctx );
270 
279 
280 #ifdef __cplusplus
281 }
282 #endif
283 #endif // _HEATER_H_
284  // End public_function group
287 
288 // ------------------------------------------------------------------------- END
heater_t
Click ctx object definition.
Definition: heater.h:125
heater_cfg_t::scl
pin_name_t scl
Definition: heater.h:150
heater_config_t::pwm
pin_name_t pwm
Definition: heater.h:168
heater_cfg_t::cs
pin_name_t cs
Definition: heater.h:157
heater_init
HEATER_RETVAL heater_init(heater_t *ctx, heater_cfg_t *cfg, heater_config_t *cfg1)
Initialization function.
heater_cfg_t
Click configuration structure definition.
Definition: heater.h:147
heater_t::cs
digital_out_t cs
Definition: heater.h:129
HEATER_RETVAL
#define HEATER_RETVAL
Definition: heater.h:81
heater_t::i2c
i2c_master_t i2c
Definition: heater.h:133
heater_cfg_t::rst
pin_name_t rst
Definition: heater.h:156
heater_config_t
Definition: heater.h:167
heater_set_duty_cycle
void heater_set_duty_cycle(heater_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
heater_set_led2_status
void heater_set_led2_status(heater_t *ctx, uint8_t status)
Sets state of the cs pin.
heater_cfg_t::i2c_address
uint8_t i2c_address
Definition: heater.h:162
heater_t::rst
digital_out_t rst
Definition: heater.h:128
heater_config_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: heater.h:170
heater_t::pwm_freq
uint32_t pwm_freq
Definition: heater.h:139
heater_t::slave_address
uint8_t slave_address
Definition: heater.h:138
heater_pwm_start
void heater_pwm_start(heater_t *ctx)
Start PWM module.
heater_read_mv
float heater_read_mv(heater_t *ctx)
Function reads data from device and converts it to mV value.
heater_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: heater.h:161
heater_read_temp
float heater_read_temp(heater_t *ctx)
Function reads data and converts it to temperature data in degree C.
heater_cfg_t::sda
pin_name_t sda
Definition: heater.h:151
heater_pwm_stop
void heater_pwm_stop(heater_t *ctx)
Stop PWM module.
heater_read_data
uint16_t heater_read_data(heater_t *ctx)
Generic function for reading data from device.
heater_set_led1_status
void heater_set_led1_status(heater_t *ctx, uint8_t status)
Sets state of the rst pin.
heater_cfg_setup
void heater_cfg_setup(heater_cfg_t *cfg, heater_config_t *cfg1)
Config Object Initialization function.
heater_t::pwm
pwm_t pwm
Definition: heater.h:134