hztov2  2.0.0.0
hztov2.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 
35 #ifndef HZTOV2_H
36 #define HZTOV2_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_analog_in.h"
41 #include "drv_pwm.h"
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
44 
54 #define HZTOV2_MAP_MIKROBUS( cfg, mikrobus ) \
55  cfg.an_pin = MIKROBUS( mikrobus, MIKROBUS_AN ); \
56  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
57  cfg.fin = MIKROBUS( mikrobus, MIKROBUS_PWM )
58 
64 #define HZTOV2_RETVAL uint8_t
65 
66 #define HZTOV2_OK 0x00
67 #define HZTOV2_INIT_ERROR 0xFF
68 
74 #define HZTOV2_DEF_FREQ 10000
75  // End group macro
78 // --------------------------------------------------------------- PUBLIC TYPES
87 typedef uint16_t hztov2_data_t;
88 
92 typedef struct
93 {
94  // Output pins
95 
96  digital_out_t en;
97 
98  // Modules
99 
100  pwm_t fin;
101  analog_in_t adc;
102 
103  // ctx variable
104 
105  uint32_t pwm_freq;
106 
107 } hztov2_t;
108 
112 typedef struct
113 {
114  // Communication gpio pins
115 
116  pin_name_t an_pin;
117  pin_name_t fin;
118 
119  // Additional gpio pins
120 
121  pin_name_t en;
122 
123  // static variable
124 
125  analog_in_resolution_t resolution; // Resolution
126  float vref; // VRef
127  uint32_t dev_pwm_freq;
128 
129 } hztov2_cfg_t;
130  // End types group
132 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
133 
139 #ifdef __cplusplus
140 extern "C"{
141 #endif
142 
151 void hztov2_cfg_setup ( hztov2_cfg_t *cfg );
152 
162 
172 
181 float hztov2_read_voltage ( hztov2_t *ctx );
182 
191 void hztov2_en_pin ( hztov2_t *ctx, uint8_t pin_state );
192 
203 HZTOV2_RETVAL hztov2_fin_set ( hztov2_t *ctx, uint32_t fin );
204 
205 #ifdef __cplusplus
206 }
207 #endif
208 #endif // _HZTOV2_H_
209  // End public_function group
212 
213 // ------------------------------------------------------------------------ END
hztov2_cfg_t::resolution
analog_in_resolution_t resolution
Definition: hztov2.h:125
hztov2_generic_read
hztov2_data_t hztov2_generic_read(hztov2_t *ctx)
Generic read function.
hztov2_cfg_t::an_pin
pin_name_t an_pin
Definition: hztov2.h:116
hztov2_read_voltage
float hztov2_read_voltage(hztov2_t *ctx)
Read voltage function.
hztov2_cfg_setup
void hztov2_cfg_setup(hztov2_cfg_t *cfg)
Config Object Initialization function.
hztov2_data_t
uint16_t hztov2_data_t
Analog data type.
Definition: hztov2.h:87
HZTOV2_RETVAL
#define HZTOV2_RETVAL
Definition: hztov2.h:64
hztov2_t::fin
pwm_t fin
Definition: hztov2.h:100
hztov2_t
Click ctx object definition.
Definition: hztov2.h:92
hztov2_cfg_t
Click configuration structure definition.
Definition: hztov2.h:112
hztov2_t::pwm_freq
uint32_t pwm_freq
Definition: hztov2.h:105
hztov2_t::adc
analog_in_t adc
Definition: hztov2.h:101
hztov2_fin_set
HZTOV2_RETVAL hztov2_fin_set(hztov2_t *ctx, uint32_t fin)
PWM frequency set function.
hztov2_en_pin
void hztov2_en_pin(hztov2_t *ctx, uint8_t pin_state)
Function for enabling the click board.
hztov2_cfg_t::fin
pin_name_t fin
Definition: hztov2.h:117
hztov2_cfg_t::en
pin_name_t en
Definition: hztov2.h:121
hztov2_cfg_t::vref
float vref
Definition: hztov2.h:126
hztov2_t::en
digital_out_t en
Definition: hztov2.h:96
hztov2_init
HZTOV2_RETVAL hztov2_init(hztov2_t *ctx, hztov2_cfg_t *cfg)
Initialization function.
hztov2_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: hztov2.h:127