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
91#define HEATER_SLAVE_ADDRESS 0x4D
98#define HEATER_LED_ON 1
99#define HEATER_LED_OFF 0
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
112#define HEATER_DEF_FREQ 500
113
114 // End group macro
115// --------------------------------------------------------------- PUBLIC TYPES
124typedef 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
139 uint32_t pwm_freq;
140
141} heater_t;
142
146typedef 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
165
166typedef struct
167{
168 pin_name_t pwm;
169
170 uint32_t dev_pwm_freq;
171
173
174 // End types group
175// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
176
182#ifdef __cplusplus
183extern "C"{
184#endif
185
195
205
213void heater_set_led1_status ( heater_t *ctx, uint8_t status );
214
222void heater_set_led2_status ( heater_t *ctx, uint8_t status );
223
231uint16_t heater_read_data ( heater_t *ctx );
232
241
250
260void heater_set_duty_cycle ( heater_t *ctx, float duty_cycle );
261
270
279
280#ifdef __cplusplus
281}
282#endif
283#endif // _HEATER_H_
284
285 // End public_function group
287
288// ------------------------------------------------------------------------- END
#define HEATER_RETVAL
Definition heater.h:81
uint16_t heater_read_data(heater_t *ctx)
Generic function for reading data from device.
void heater_set_led1_status(heater_t *ctx, uint8_t status)
Sets state of the rst pin.
void heater_pwm_stop(heater_t *ctx)
Stop PWM module.
void heater_cfg_setup(heater_cfg_t *cfg, heater_config_t *cfg1)
Config Object Initialization function.
void heater_set_duty_cycle(heater_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
float heater_read_temp(heater_t *ctx)
Function reads data and converts it to temperature data in degree C.
HEATER_RETVAL heater_init(heater_t *ctx, heater_cfg_t *cfg, heater_config_t *cfg1)
Initialization function.
float heater_read_mv(heater_t *ctx)
Function reads data from device and converts it to mV value.
void heater_set_led2_status(heater_t *ctx, uint8_t status)
Sets state of the cs pin.
void heater_pwm_start(heater_t *ctx)
Start PWM module.
Click configuration structure definition.
Definition heater.h:147
uint32_t i2c_speed
Definition heater.h:161
pin_name_t scl
Definition heater.h:150
pin_name_t sda
Definition heater.h:151
pin_name_t rst
Definition heater.h:156
pin_name_t cs
Definition heater.h:157
uint8_t i2c_address
Definition heater.h:162
Definition heater.h:167
uint32_t dev_pwm_freq
Definition heater.h:170
pin_name_t pwm
Definition heater.h:168
Click ctx object definition.
Definition heater.h:125
digital_out_t cs
Definition heater.h:129
uint32_t pwm_freq
Definition heater.h:139
i2c_master_t i2c
Definition heater.h:133
digital_out_t rst
Definition heater.h:128
uint8_t slave_address
Definition heater.h:138
pwm_t pwm
Definition heater.h:134