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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_pwm.h"
41 #include "drv_analog_in.h"
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define HZTOV_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
55  cfg.vo = MIKROBUS( mikrobus, MIKROBUS_AN ); \
56  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS )
57 
63 #define HZTOV_RETVAL uint8_t
64 
65 #define HZTOV_OK 0x00
66 #define HZTOV_INIT_ERROR 0xFF
67 
73 #define HZTOV_DEF_FREQ 5000
74 
80 #define HZTOV_ENABLE 1
81 #define HZTOV_DISABLE 0
82 
89 #define HZTOV_MAX_FREQ 10000
90 #define HZTOV_MIN_FREQ 1000
91  // End group macro
95 // --------------------------------------------------------------- PUBLIC TYPES
104 typedef uint16_t hztov_data_t;
105 
109 typedef struct
110 {
111  // Output pins
112 
113  digital_out_t en;
114 
115  // Modules
116 
117  pwm_t pwm;
118  analog_in_t adc;
119 
120  // ctx variable
121 
122  uint32_t pwm_freq;
123 
124 } hztov_t;
125 
129 typedef struct
130 {
131  // Communication gpio pins
132 
133  pin_name_t pwm;
134  pin_name_t vo;
135 
136  // Additional gpio pins
137 
138  pin_name_t en;
139 
140  // static variable
141 
142  analog_in_resolution_t resolution; // Resolution
143  float vref; // VRef
144  uint32_t dev_pwm_freq;
145 } hztov_cfg_t;
146  // End types group
148 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
149 
155 #ifdef __cplusplus
156 extern "C"{
157 #endif
158 
168 
177 
187 
197 
206 void hztov_set_enable ( hztov_t *ctx, uint8_t state );
207 
217 void hztov_set_duty_cycle ( hztov_t *ctx, float duty_cycle );
218 
226 void hztov_pwm_stop ( hztov_t *ctx );
227 
235 void hztov_pwm_start ( hztov_t *ctx );
236 
245 void hztov_set_input_frequency ( hztov_t *ctx, uint16_t freq );
246 
247 #ifdef __cplusplus
248 }
249 #endif
250 #endif // _HZTOV_H_
251  // End public_function group
254 
255 // ------------------------------------------------------------------------- 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:142
hztov_cfg_t::en
pin_name_t en
Definition: hztov.h:138
hztov_cfg_t::pwm
pin_name_t pwm
Definition: hztov.h:133
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:134
hztov_cfg_t::vref
float vref
Definition: hztov.h:143
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:104
hztov_t::pwm
pwm_t pwm
Definition: hztov.h:117
hztov_t::adc
analog_in_t adc
Definition: hztov.h:118
HZTOV_RETVAL
#define HZTOV_RETVAL
Definition: hztov.h:63
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:130
hztov_t
Click ctx object definition.
Definition: hztov.h:110
hztov_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: hztov.h:144
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:113
hztov_read_voltage
float hztov_read_voltage(hztov_t *ctx)
Read voltage function.
hztov_t::pwm_freq
uint32_t pwm_freq
Definition: hztov.h:122
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.