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 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 #include "spi_specifics.h"
49 #include "drv_analog_in.h"
50 
71 #define VTOHZ3_MAXIMAL_IN_FREQUENCY 1000000
72 #define VTOHZ3_MINIMAL_IN_FREQUENCY 32000
73 #define VTOHZ3_DEFAULT_IN_FREQUENCY 100000
74 
79 #define VTOHZ3_VREF_3V3 3.3
80 #define VTOHZ3_VREF_5V 5.0
81 #define VTOHZ3_VREF_INTERNAL_2V5 2.5
82 
91 #define VTOHZ3_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
92 #define VTOHZ3_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
93  // vtohz3_set
95 
110 #define VTOHZ3_MAP_MIKROBUS( cfg, mikrobus ) \
111  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
112  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
113  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
114  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
115  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
116  cfg.buf = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
117  cfg.fout = MIKROBUS( mikrobus, MIKROBUS_INT )
118  // vtohz3_map // vtohz3
121 
126 typedef struct
127 {
128  // Output pins
129  digital_out_t buf;
131  // Input pins
132  digital_in_t fout;
134  // Modules
135  spi_master_t spi;
136  analog_in_t adc;
138  pin_name_t chip_select;
140  uint32_t clock_in_freq;
142 } vtohz3_t;
143 
148 typedef struct
149 {
150  // Communication gpio pins
151  pin_name_t miso;
152  pin_name_t mosi;
153  pin_name_t sck;
154  pin_name_t cs;
155  pin_name_t an;
157  // Additional gpio pins
158  pin_name_t buf;
159  pin_name_t fout;
161  // static variable
162  uint32_t spi_speed;
163  spi_master_mode_t spi_mode;
164  spi_master_chip_select_polarity_t cs_polarity;
166  analog_in_resolution_t resolution;
167  float vref;
169 } vtohz3_cfg_t;
170 
175 typedef enum
176 {
178  VTOHZ3_ERROR = -1
179 
181 
198 
212 err_t vtohz3_init ( vtohz3_t *ctx, vtohz3_cfg_t *cfg );
213 
227 err_t vtohz3_set_input_frequency ( vtohz3_t *ctx, uint32_t freq );
228 
241 
251 void vtohz3_set_buf_pin ( vtohz3_t *ctx, uint8_t state );
252 
261 uint8_t vtohz3_get_fout_pin ( vtohz3_t *ctx );
262 
274 err_t vtohz3_read_an_pin_value ( vtohz3_t *ctx, uint16_t *data_out );
275 
289 err_t vtohz3_read_an_pin_voltage ( vtohz3_t *ctx, float *data_out );
290 
301 uint32_t vtohz3_get_frequency ( vtohz3_t *ctx, float voltage, float vref_in );
302 
303 #ifdef __cplusplus
304 }
305 #endif
306 #endif // VTOHZ3_H
307  // vtohz3
309 
310 // ------------------------------------------------------------------------ END
vtohz3_return_value_t
vtohz3_return_value_t
V to Hz 3 Click return value data.
Definition: vtohz3.h:176
vtohz3_t::buf
digital_out_t buf
Definition: vtohz3.h:129
vtohz3_cfg_t::miso
pin_name_t miso
Definition: vtohz3.h:151
vtohz3_t::adc
analog_in_t adc
Definition: vtohz3.h:136
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:177
vtohz3_cfg_t::cs
pin_name_t cs
Definition: vtohz3.h:154
vtohz3_t::chip_select
pin_name_t chip_select
Definition: vtohz3.h:138
vtohz3_cfg_t::mosi
pin_name_t mosi
Definition: vtohz3.h:152
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:167
vtohz3_t
V to Hz 3 Click context object.
Definition: vtohz3.h:127
vtohz3_cfg_t::spi_speed
uint32_t spi_speed
Definition: vtohz3.h:162
vtohz3_t::clock_in_freq
uint32_t clock_in_freq
Definition: vtohz3.h:140
vtohz3_cfg_t::sck
pin_name_t sck
Definition: vtohz3.h:153
vtohz3_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: vtohz3.h:163
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:164
vtohz3_cfg_t::buf
pin_name_t buf
Definition: vtohz3.h:158
VTOHZ3_ERROR
@ VTOHZ3_ERROR
Definition: vtohz3.h:178
vtohz3_cfg_t::an
pin_name_t an
Definition: vtohz3.h:155
vtohz3_cfg_t::fout
pin_name_t fout
Definition: vtohz3.h:159
vtohz3_t::fout
digital_in_t fout
Definition: vtohz3.h:132
vtohz3_cfg_t
V to Hz 3 Click configuration object.
Definition: vtohz3.h:149
vtohz3_cfg_t::resolution
analog_in_resolution_t resolution
Definition: vtohz3.h:166
vtohz3_t::spi
spi_master_t spi
Definition: vtohz3.h:135
vtohz3_disable_input_frequency
err_t vtohz3_disable_input_frequency(vtohz3_t *ctx)
V to Hz 3 disable input frequency function.