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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 #include "drv_pwm.h"
42 
43 
44 // -------------------------------------------------------------- PUBLIC MACROS
54 #define HEATER_MAP_MIKROBUS( cfg, mikrobus ) \
55  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
56  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
57  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
58  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
59  cfg1.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
60 
67 #define HEATER_RETVAL uint8_t
68 
69 #define HEATER_OK 0x00
70 #define HEATER_INIT_ERROR 0xFF
71 
77 #define HEATER_SLAVE_ADDRESS 0x4D
78 
84 #define HEATER_LED_ON 1
85 #define HEATER_LED_OFF 0
86 
91 #define HEATER_SHIFT_DATA 8
92 #define HEATER_ADC_VREF 3300.00f
93 #define HEATER_MV_RESOLUTION 4096.00f
94 #define HEATER_TEMP_RESOLUTION 10.0f
95 #define HEATER_TEMP_0 500.0
96 
98 #define HEATER_DEF_FREQ 500
99  // End group macro
101 // --------------------------------------------------------------- PUBLIC TYPES
110 typedef struct
111 {
112  // Output pins
113 
114  digital_out_t rst;
115  digital_out_t cs;
116 
117  // Modules
118 
119  i2c_master_t i2c;
120  pwm_t pwm;
121 
122  // ctx variable
123 
124  uint8_t slave_address;
125  uint32_t pwm_freq;
126 
127 } heater_t;
128 
132 typedef struct
133 {
134  // Communication gpio pins
135 
136  pin_name_t scl;
137  pin_name_t sda;
138 
139 
140  // Additional gpio pins
141 
142  pin_name_t rst;
143  pin_name_t cs;
144 
145  // static variable
146 
147  uint32_t i2c_speed;
148  uint8_t i2c_address;
149 
150 } heater_cfg_t;
151 
152 typedef struct
153 {
154  pin_name_t pwm;
155 
156  uint32_t dev_pwm_freq;
157 
159  // End types group
161 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
162 
168 #ifdef __cplusplus
169 extern "C"{
170 #endif
171 
181 
191 
199 void heater_set_led1_status ( heater_t *ctx, uint8_t status );
200 
208 void heater_set_led2_status ( heater_t *ctx, uint8_t status );
209 
217 uint16_t heater_read_data ( heater_t *ctx );
218 
226 float heater_read_mv ( heater_t *ctx );
227 
235 float heater_read_temp ( heater_t *ctx );
236 
246 void heater_set_duty_cycle ( heater_t *ctx, float duty_cycle );
247 
255 void heater_pwm_stop ( heater_t *ctx );
256 
265 
266 #ifdef __cplusplus
267 }
268 #endif
269 #endif // _HEATER_H_
270  // End public_function group
273 
274 // ------------------------------------------------------------------------- END
heater_t
Click ctx object definition.
Definition: heater.h:111
heater_cfg_t::scl
pin_name_t scl
Definition: heater.h:136
heater_config_t::pwm
pin_name_t pwm
Definition: heater.h:154
heater_cfg_t::cs
pin_name_t cs
Definition: heater.h:143
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:133
heater_t::cs
digital_out_t cs
Definition: heater.h:115
HEATER_RETVAL
#define HEATER_RETVAL
Definition: heater.h:67
heater_t::i2c
i2c_master_t i2c
Definition: heater.h:119
heater_cfg_t::rst
pin_name_t rst
Definition: heater.h:142
heater_config_t
Definition: heater.h:153
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:148
heater_t::rst
digital_out_t rst
Definition: heater.h:114
heater_config_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: heater.h:156
heater_t::pwm_freq
uint32_t pwm_freq
Definition: heater.h:125
heater_t::slave_address
uint8_t slave_address
Definition: heater.h:124
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:147
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:137
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:120