vtohz3 2.0.0.0
vtohz3.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef VTOHZ3_H
29#define VTOHZ3_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
52#include "spi_specifics.h"
53#include "drv_analog_in.h"
54
75#define VTOHZ3_MAXIMAL_IN_FREQUENCY 1000000
76#define VTOHZ3_MINIMAL_IN_FREQUENCY 32000
77#define VTOHZ3_DEFAULT_IN_FREQUENCY 100000
78
83#define VTOHZ3_VREF_3V3 3.3
84#define VTOHZ3_VREF_5V 5.0
85#define VTOHZ3_VREF_INTERNAL_2V5 2.5
86
95#define VTOHZ3_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
96#define VTOHZ3_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
97
98 // vtohz3_set
99
114#define VTOHZ3_MAP_MIKROBUS( cfg, mikrobus ) \
115 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
116 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
117 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
118 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
119 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
120 cfg.buf = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
121 cfg.fout = MIKROBUS( mikrobus, MIKROBUS_INT )
122
123 // vtohz3_map
124 // vtohz3
125
130typedef struct
131{
132 // Output pins
133 digital_out_t buf;
135 // Input pins
136 digital_in_t fout;
138 // Modules
139 spi_master_t spi;
140 analog_in_t adc;
142 pin_name_t chip_select;
144 uint32_t clock_in_freq;
146} vtohz3_t;
147
152typedef struct
153{
154 // Communication gpio pins
155 pin_name_t miso;
156 pin_name_t mosi;
157 pin_name_t sck;
158 pin_name_t cs;
159 pin_name_t an;
161 // Additional gpio pins
162 pin_name_t buf;
163 pin_name_t fout;
165 // static variable
166 uint32_t spi_speed;
167 spi_master_mode_t spi_mode;
168 spi_master_chip_select_polarity_t cs_polarity;
170 analog_in_resolution_t resolution;
171 float vref;
174
179typedef enum
180{
182 VTOHZ3_ERROR = -1
183
185
202
216err_t vtohz3_init ( vtohz3_t *ctx, vtohz3_cfg_t *cfg );
217
231err_t vtohz3_set_input_frequency ( vtohz3_t *ctx, uint32_t freq );
232
245
255void vtohz3_set_buf_pin ( vtohz3_t *ctx, uint8_t state );
256
266
278err_t vtohz3_read_an_pin_value ( vtohz3_t *ctx, uint16_t *data_out );
279
293err_t vtohz3_read_an_pin_voltage ( vtohz3_t *ctx, float *data_out );
294
305uint32_t vtohz3_get_frequency ( vtohz3_t *ctx, float voltage, float vref_in );
306
307#ifdef __cplusplus
308}
309#endif
310#endif // VTOHZ3_H
311
312 // vtohz3
313
314// ------------------------------------------------------------------------ END
err_t vtohz3_read_an_pin_voltage(vtohz3_t *ctx, float *data_out)
V to Hz 3 read AN pin voltage level function.
err_t vtohz3_disable_input_frequency(vtohz3_t *ctx)
V to Hz 3 disable input frequency function.
void vtohz3_set_buf_pin(vtohz3_t *ctx, uint8_t state)
V to Hz 3 set buf pin function.
err_t vtohz3_set_input_frequency(vtohz3_t *ctx, uint32_t freq)
V to Hz 3 set input frequency function.
err_t vtohz3_read_an_pin_value(vtohz3_t *ctx, uint16_t *data_out)
V to Hz 3 read AN pin value function.
uint8_t vtohz3_get_fout_pin(vtohz3_t *ctx)
V to Hz 3 get fout pin function.
uint32_t vtohz3_get_frequency(vtohz3_t *ctx, float voltage, float vref_in)
V to Hz 3 get frequency function.
void vtohz3_cfg_setup(vtohz3_cfg_t *cfg)
V to Hz 3 configuration object setup function.
err_t vtohz3_init(vtohz3_t *ctx, vtohz3_cfg_t *cfg)
V to Hz 3 initialization function.
This file contains SPI specific macros, functions, etc.
V to Hz 3 Click configuration object.
Definition vtohz3.h:153
pin_name_t buf
Definition vtohz3.h:162
analog_in_resolution_t resolution
Definition vtohz3.h:170
float vref
Definition vtohz3.h:171
pin_name_t fout
Definition vtohz3.h:163
spi_master_chip_select_polarity_t cs_polarity
Definition vtohz3.h:168
pin_name_t sck
Definition vtohz3.h:157
spi_master_mode_t spi_mode
Definition vtohz3.h:167
pin_name_t mosi
Definition vtohz3.h:156
uint32_t spi_speed
Definition vtohz3.h:166
pin_name_t miso
Definition vtohz3.h:155
pin_name_t an
Definition vtohz3.h:159
pin_name_t cs
Definition vtohz3.h:158
V to Hz 3 Click context object.
Definition vtohz3.h:131
spi_master_t spi
Definition vtohz3.h:139
digital_out_t buf
Definition vtohz3.h:133
uint32_t clock_in_freq
Definition vtohz3.h:144
digital_in_t fout
Definition vtohz3.h:136
pin_name_t chip_select
Definition vtohz3.h:142
analog_in_t adc
Definition vtohz3.h:140
vtohz3_return_value_t
V to Hz 3 Click return value data.
Definition vtohz3.h:180
@ VTOHZ3_ERROR
Definition vtohz3.h:182
@ VTOHZ3_OK
Definition vtohz3.h:181