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
32 extern "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  // 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  // vtohz3_map // vtohz3
125 
130 typedef 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 
152 typedef 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;
173 } vtohz3_cfg_t;
174 
179 typedef enum
180 {
182  VTOHZ3_ERROR = -1
183 
185 
202 
216 err_t vtohz3_init ( vtohz3_t *ctx, vtohz3_cfg_t *cfg );
217 
231 err_t vtohz3_set_input_frequency ( vtohz3_t *ctx, uint32_t freq );
232 
245 
255 void vtohz3_set_buf_pin ( vtohz3_t *ctx, uint8_t state );
256 
265 uint8_t vtohz3_get_fout_pin ( vtohz3_t *ctx );
266 
278 err_t vtohz3_read_an_pin_value ( vtohz3_t *ctx, uint16_t *data_out );
279 
293 err_t vtohz3_read_an_pin_voltage ( vtohz3_t *ctx, float *data_out );
294 
305 uint32_t vtohz3_get_frequency ( vtohz3_t *ctx, float voltage, float vref_in );
306 
307 #ifdef __cplusplus
308 }
309 #endif
310 #endif // VTOHZ3_H
311  // vtohz3
313 
314 // ------------------------------------------------------------------------ END
vtohz3_return_value_t
vtohz3_return_value_t
V to Hz 3 Click return value data.
Definition: vtohz3.h:180
vtohz3_t::buf
digital_out_t buf
Definition: vtohz3.h:133
vtohz3_cfg_t::miso
pin_name_t miso
Definition: vtohz3.h:155
vtohz3_t::adc
analog_in_t adc
Definition: vtohz3.h:140
spi_specifics.h
This file contains SPI specific macros, functions, etc.
vtohz3_read_an_pin_voltage
err_t vtohz3_read_an_pin_voltage(vtohz3_t *ctx, float *data_out)
V to Hz 3 read AN pin voltage level function.
vtohz3_set_buf_pin
void vtohz3_set_buf_pin(vtohz3_t *ctx, uint8_t state)
V to Hz 3 set buf pin function.
VTOHZ3_OK
@ VTOHZ3_OK
Definition: vtohz3.h:181
vtohz3_cfg_t::cs
pin_name_t cs
Definition: vtohz3.h:158
vtohz3_t::chip_select
pin_name_t chip_select
Definition: vtohz3.h:142
vtohz3_cfg_t::mosi
pin_name_t mosi
Definition: vtohz3.h:156
vtohz3_read_an_pin_value
err_t vtohz3_read_an_pin_value(vtohz3_t *ctx, uint16_t *data_out)
V to Hz 3 read AN pin value function.
vtohz3_init
err_t vtohz3_init(vtohz3_t *ctx, vtohz3_cfg_t *cfg)
V to Hz 3 initialization function.
vtohz3_cfg_t::vref
float vref
Definition: vtohz3.h:171
vtohz3_t
V to Hz 3 Click context object.
Definition: vtohz3.h:131
vtohz3_cfg_t::spi_speed
uint32_t spi_speed
Definition: vtohz3.h:166
vtohz3_t::clock_in_freq
uint32_t clock_in_freq
Definition: vtohz3.h:144
vtohz3_cfg_t::sck
pin_name_t sck
Definition: vtohz3.h:157
vtohz3_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: vtohz3.h:167
vtohz3_get_fout_pin
uint8_t vtohz3_get_fout_pin(vtohz3_t *ctx)
V to Hz 3 get fout pin function.
vtohz3_get_frequency
uint32_t vtohz3_get_frequency(vtohz3_t *ctx, float voltage, float vref_in)
V to Hz 3 get frequency function.
vtohz3_cfg_setup
void vtohz3_cfg_setup(vtohz3_cfg_t *cfg)
V to Hz 3 configuration object setup function.
vtohz3_set_input_frequency
err_t vtohz3_set_input_frequency(vtohz3_t *ctx, uint32_t freq)
V to Hz 3 set input frequency function.
vtohz3_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: vtohz3.h:168
vtohz3_cfg_t::buf
pin_name_t buf
Definition: vtohz3.h:162
VTOHZ3_ERROR
@ VTOHZ3_ERROR
Definition: vtohz3.h:182
vtohz3_cfg_t::an
pin_name_t an
Definition: vtohz3.h:159
vtohz3_cfg_t::fout
pin_name_t fout
Definition: vtohz3.h:163
vtohz3_t::fout
digital_in_t fout
Definition: vtohz3.h:136
vtohz3_cfg_t
V to Hz 3 Click configuration object.
Definition: vtohz3.h:153
vtohz3_cfg_t::resolution
analog_in_resolution_t resolution
Definition: vtohz3.h:170
vtohz3_t::spi
spi_master_t spi
Definition: vtohz3.h:139
vtohz3_disable_input_frequency
err_t vtohz3_disable_input_frequency(vtohz3_t *ctx)
V to Hz 3 disable input frequency function.