hztov  2.0.0.0
hztov.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 HZTOV_H
36 #define HZTOV_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_pwm.h"
55 #include "drv_analog_in.h"
56 
57 // -------------------------------------------------------------- PUBLIC MACROS
67 #define HZTOV_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
69  cfg.vo = MIKROBUS( mikrobus, MIKROBUS_AN ); \
70  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS )
71 
77 #define HZTOV_RETVAL uint8_t
78 
79 #define HZTOV_OK 0x00
80 #define HZTOV_INIT_ERROR 0xFF
81 
87 #define HZTOV_DEF_FREQ 5000
88 
94 #define HZTOV_ENABLE 1
95 #define HZTOV_DISABLE 0
96 
103 #define HZTOV_MAX_FREQ 10000
104 #define HZTOV_MIN_FREQ 1000
105  // End group macro
109 // --------------------------------------------------------------- PUBLIC TYPES
118 typedef uint16_t hztov_data_t;
119 
123 typedef struct
124 {
125  // Output pins
126 
127  digital_out_t en;
128 
129  // Modules
130 
131  pwm_t pwm;
132  analog_in_t adc;
133 
134  // ctx variable
135 
136  uint32_t pwm_freq;
137 
138 } hztov_t;
139 
143 typedef struct
144 {
145  // Communication gpio pins
146 
147  pin_name_t pwm;
148  pin_name_t vo;
149 
150  // Additional gpio pins
151 
152  pin_name_t en;
153 
154  // static variable
155 
156  analog_in_resolution_t resolution; // Resolution
157  float vref; // VRef
158  uint32_t dev_pwm_freq;
159 } hztov_cfg_t;
160  // End types group
162 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
163 
169 #ifdef __cplusplus
170 extern "C"{
171 #endif
172 
182 
191 
201 
211 
220 void hztov_set_enable ( hztov_t *ctx, uint8_t state );
221 
231 void hztov_set_duty_cycle ( hztov_t *ctx, float duty_cycle );
232 
240 void hztov_pwm_stop ( hztov_t *ctx );
241 
249 void hztov_pwm_start ( hztov_t *ctx );
250 
259 void hztov_set_input_frequency ( hztov_t *ctx, uint16_t freq );
260 
261 #ifdef __cplusplus
262 }
263 #endif
264 #endif // _HZTOV_H_
265  // End public_function group
268 
269 // ------------------------------------------------------------------------- END
hztov_init
HZTOV_RETVAL hztov_init(hztov_t *ctx, hztov_cfg_t *cfg)
Initialization function.
hztov_cfg_t::resolution
analog_in_resolution_t resolution
Definition: hztov.h:156
hztov_cfg_t::en
pin_name_t en
Definition: hztov.h:152
hztov_cfg_t::pwm
pin_name_t pwm
Definition: hztov.h:147
hztov_cfg_setup
void hztov_cfg_setup(hztov_cfg_t *cfg)
Config Object Initialization function.
hztov_cfg_t::vo
pin_name_t vo
Definition: hztov.h:148
hztov_cfg_t::vref
float vref
Definition: hztov.h:157
hztov_set_input_frequency
void hztov_set_input_frequency(hztov_t *ctx, uint16_t freq)
Changing the output voltage function.
hztov_data_t
uint16_t hztov_data_t
Analog data type.
Definition: hztov.h:118
hztov_t::pwm
pwm_t pwm
Definition: hztov.h:131
hztov_t::adc
analog_in_t adc
Definition: hztov.h:132
HZTOV_RETVAL
#define HZTOV_RETVAL
Definition: hztov.h:77
hztov_set_enable
void hztov_set_enable(hztov_t *ctx, uint8_t state)
Set enable pin state.
hztov_cfg_t
Click configuration structure definition.
Definition: hztov.h:144
hztov_t
Click ctx object definition.
Definition: hztov.h:124
hztov_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: hztov.h:158
hztov_set_duty_cycle
void hztov_set_duty_cycle(hztov_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
hztov_t::en
digital_out_t en
Definition: hztov.h:127
hztov_read_voltage
float hztov_read_voltage(hztov_t *ctx)
Read voltage function.
hztov_t::pwm_freq
uint32_t pwm_freq
Definition: hztov.h:136
hztov_pwm_stop
void hztov_pwm_stop(hztov_t *ctx)
Stop PWM module.
hztov_pwm_start
void hztov_pwm_start(hztov_t *ctx)
Start PWM module.
hztov_generic_read
hztov_data_t hztov_generic_read(hztov_t *ctx)
Generic read function.