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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_pwm.h"
51 #include "drv_analog_in.h"
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define HZTOV_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
65  cfg.vo = MIKROBUS( mikrobus, MIKROBUS_AN ); \
66  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS )
67 
73 #define HZTOV_RETVAL uint8_t
74 
75 #define HZTOV_OK 0x00
76 #define HZTOV_INIT_ERROR 0xFF
77 
83 #define HZTOV_DEF_FREQ 5000
84 
90 #define HZTOV_ENABLE 1
91 #define HZTOV_DISABLE 0
92 
99 #define HZTOV_MAX_FREQ 10000
100 #define HZTOV_MIN_FREQ 1000
101  // End group macro
105 // --------------------------------------------------------------- PUBLIC TYPES
114 typedef uint16_t hztov_data_t;
115 
119 typedef struct
120 {
121  // Output pins
122 
123  digital_out_t en;
124 
125  // Modules
126 
127  pwm_t pwm;
128  analog_in_t adc;
129 
130  // ctx variable
131 
132  uint32_t pwm_freq;
133 
134 } hztov_t;
135 
139 typedef struct
140 {
141  // Communication gpio pins
142 
143  pin_name_t pwm;
144  pin_name_t vo;
145 
146  // Additional gpio pins
147 
148  pin_name_t en;
149 
150  // static variable
151 
152  analog_in_resolution_t resolution; // Resolution
153  float vref; // VRef
154  uint32_t dev_pwm_freq;
155 } hztov_cfg_t;
156  // End types group
158 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
159 
165 #ifdef __cplusplus
166 extern "C"{
167 #endif
168 
178 
187 
197 
207 
216 void hztov_set_enable ( hztov_t *ctx, uint8_t state );
217 
227 void hztov_set_duty_cycle ( hztov_t *ctx, float duty_cycle );
228 
236 void hztov_pwm_stop ( hztov_t *ctx );
237 
245 void hztov_pwm_start ( hztov_t *ctx );
246 
255 void hztov_set_input_frequency ( hztov_t *ctx, uint16_t freq );
256 
257 #ifdef __cplusplus
258 }
259 #endif
260 #endif // _HZTOV_H_
261  // End public_function group
264 
265 // ------------------------------------------------------------------------- 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:152
hztov_cfg_t::en
pin_name_t en
Definition: hztov.h:148
hztov_cfg_t::pwm
pin_name_t pwm
Definition: hztov.h:143
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:144
hztov_cfg_t::vref
float vref
Definition: hztov.h:153
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:114
hztov_t::pwm
pwm_t pwm
Definition: hztov.h:127
hztov_t::adc
analog_in_t adc
Definition: hztov.h:128
HZTOV_RETVAL
#define HZTOV_RETVAL
Definition: hztov.h:73
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:140
hztov_t
Click ctx object definition.
Definition: hztov.h:120
hztov_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: hztov.h:154
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:123
hztov_read_voltage
float hztov_read_voltage(hztov_t *ctx)
Read voltage function.
hztov_t::pwm_freq
uint32_t pwm_freq
Definition: hztov.h:132
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.