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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 #include "drv_analog_in.h"
40 
61 #define VTOHZ3_MAXIMAL_IN_FREQUENCY 1000000
62 #define VTOHZ3_MINIMAL_IN_FREQUENCY 32000
63 #define VTOHZ3_DEFAULT_IN_FREQUENCY 100000
64 
69 #define VTOHZ3_VREF_3V3 3.3
70 #define VTOHZ3_VREF_5V 5.0
71 #define VTOHZ3_VREF_INTERNAL_2V5 2.5
72 
81 #define VTOHZ3_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
82 #define VTOHZ3_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
83  // vtohz3_set
85 
100 #define VTOHZ3_MAP_MIKROBUS( cfg, mikrobus ) \
101  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
102  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
103  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
104  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
105  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
106  cfg.buf = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
107  cfg.fout = MIKROBUS( mikrobus, MIKROBUS_INT )
108  // vtohz3_map // vtohz3
111 
116 typedef struct
117 {
118  // Output pins
119  digital_out_t buf;
121  // Input pins
122  digital_in_t fout;
124  // Modules
125  spi_master_t spi;
126  analog_in_t adc;
128  pin_name_t chip_select;
130  uint32_t clock_in_freq;
132 } vtohz3_t;
133 
138 typedef struct
139 {
140  // Communication gpio pins
141  pin_name_t miso;
142  pin_name_t mosi;
143  pin_name_t sck;
144  pin_name_t cs;
145  pin_name_t an;
147  // Additional gpio pins
148  pin_name_t buf;
149  pin_name_t fout;
151  // static variable
152  uint32_t spi_speed;
153  spi_master_mode_t spi_mode;
154  spi_master_chip_select_polarity_t cs_polarity;
156  analog_in_resolution_t resolution;
157  float vref;
159 } vtohz3_cfg_t;
160 
165 typedef enum
166 {
168  VTOHZ3_ERROR = -1
169 
171 
188 
202 err_t vtohz3_init ( vtohz3_t *ctx, vtohz3_cfg_t *cfg );
203 
217 err_t vtohz3_set_input_frequency ( vtohz3_t *ctx, uint32_t freq );
218 
231 
241 void vtohz3_set_buf_pin ( vtohz3_t *ctx, uint8_t state );
242 
251 uint8_t vtohz3_get_fout_pin ( vtohz3_t *ctx );
252 
264 err_t vtohz3_read_an_pin_value ( vtohz3_t *ctx, uint16_t *data_out );
265 
279 err_t vtohz3_read_an_pin_voltage ( vtohz3_t *ctx, float *data_out );
280 
291 uint32_t vtohz3_get_frequency ( vtohz3_t *ctx, float voltage, float vref_in );
292 
293 #ifdef __cplusplus
294 }
295 #endif
296 #endif // VTOHZ3_H
297  // vtohz3
299 
300 // ------------------------------------------------------------------------ END
vtohz3_return_value_t
vtohz3_return_value_t
V to Hz 3 Click return value data.
Definition: vtohz3.h:166
vtohz3_t::buf
digital_out_t buf
Definition: vtohz3.h:119
vtohz3_cfg_t::miso
pin_name_t miso
Definition: vtohz3.h:141
vtohz3_t::adc
analog_in_t adc
Definition: vtohz3.h:126
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:167
vtohz3_cfg_t::cs
pin_name_t cs
Definition: vtohz3.h:144
vtohz3_t::chip_select
pin_name_t chip_select
Definition: vtohz3.h:128
vtohz3_cfg_t::mosi
pin_name_t mosi
Definition: vtohz3.h:142
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:157
vtohz3_t
V to Hz 3 Click context object.
Definition: vtohz3.h:117
vtohz3_cfg_t::spi_speed
uint32_t spi_speed
Definition: vtohz3.h:152
vtohz3_t::clock_in_freq
uint32_t clock_in_freq
Definition: vtohz3.h:130
vtohz3_cfg_t::sck
pin_name_t sck
Definition: vtohz3.h:143
vtohz3_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: vtohz3.h:153
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:154
vtohz3_cfg_t::buf
pin_name_t buf
Definition: vtohz3.h:148
VTOHZ3_ERROR
@ VTOHZ3_ERROR
Definition: vtohz3.h:168
vtohz3_cfg_t::an
pin_name_t an
Definition: vtohz3.h:145
vtohz3_cfg_t::fout
pin_name_t fout
Definition: vtohz3.h:149
vtohz3_t::fout
digital_in_t fout
Definition: vtohz3.h:122
vtohz3_cfg_t
V to Hz 3 Click configuration object.
Definition: vtohz3.h:139
vtohz3_cfg_t::resolution
analog_in_resolution_t resolution
Definition: vtohz3.h:156
vtohz3_t::spi
spi_master_t spi
Definition: vtohz3.h:125
vtohz3_disable_input_frequency
err_t vtohz3_disable_input_frequency(vtohz3_t *ctx)
V to Hz 3 disable input frequency function.