vumeter  2.0.0.0
vumeter.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 VUMETER_H
29 #define VUMETER_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 VUMETER_GAIN_LEVEL_MAX 0xFF
62 #define VUMETER_GAIN_LEVEL_MID 0x80
63 #define VUMETER_GAIN_LEVEL_MIN 0x00
64 
69 #define VUMETER_DBU_VREF 0.7746
70 #define VUMETER_DBU_TO_VU 4.0
71 #define VUMETER_RMS_FOR_20VU 0.123
72 #define VUMETER_VOLTAGE_OFFSET 2.5
73 #define VUMETER_MIN_VU -20.0
74 
83 #define VUMETER_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
84 #define VUMETER_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
85  // vumeter_set
87 
102 #define VUMETER_MAP_MIKROBUS( cfg, mikrobus ) \
103  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
104  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
105  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
106  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
107  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN )
108  // vumeter_map // vumeter
111 
116 typedef struct
117 {
118  // Modules
119  spi_master_t spi;
120  analog_in_t adc;
122  pin_name_t chip_select;
124 } vumeter_t;
125 
130 typedef struct
131 {
132  // Communication gpio pins
133  pin_name_t miso;
134  pin_name_t mosi;
135  pin_name_t sck;
136  pin_name_t cs;
137  pin_name_t an;
139  // static variable
140  uint32_t spi_speed;
141  spi_master_mode_t spi_mode;
142  spi_master_chip_select_polarity_t cs_polarity;
144  analog_in_resolution_t resolution;
145  float vref;
147 } vumeter_cfg_t;
148 
153 typedef enum
154 {
156  VUMETER_ERROR = -1
157 
159 
176 
191 err_t vumeter_init ( vumeter_t *ctx, vumeter_cfg_t *cfg );
192 
205 err_t vumeter_read_an_pin_value ( vumeter_t *ctx, uint16_t *data_out );
206 
221 err_t vumeter_read_an_pin_voltage ( vumeter_t *ctx, float *data_out );
222 
235 err_t vumeter_set_gain_level ( vumeter_t *ctx, uint8_t gain_lvl );
236 
248 float vumeter_calculate_vu_level ( vumeter_t *ctx, uint16_t sample_rate_ms );
249 
250 #ifdef __cplusplus
251 }
252 #endif
253 #endif // VUMETER_H
254  // vumeter
256 
257 // ------------------------------------------------------------------------ END
vumeter_cfg_setup
void vumeter_cfg_setup(vumeter_cfg_t *cfg)
VU Meter configuration object setup function.
vumeter_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: vumeter.h:141
vumeter_read_an_pin_value
err_t vumeter_read_an_pin_value(vumeter_t *ctx, uint16_t *data_out)
VU Meter read AN pin value function.
vumeter_init
err_t vumeter_init(vumeter_t *ctx, vumeter_cfg_t *cfg)
VU Meter initialization function.
vumeter_t::spi
spi_master_t spi
Definition: vumeter.h:119
vumeter_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: vumeter.h:142
spi_specifics.h
This file contains SPI specific macros, functions, etc.
vumeter_return_value_t
vumeter_return_value_t
VU Meter Click return value data.
Definition: vumeter.h:154
VUMETER_OK
@ VUMETER_OK
Definition: vumeter.h:155
vumeter_t
VU Meter Click context object.
Definition: vumeter.h:117
vumeter_cfg_t::sck
pin_name_t sck
Definition: vumeter.h:135
vumeter_cfg_t::spi_speed
uint32_t spi_speed
Definition: vumeter.h:140
VUMETER_ERROR
@ VUMETER_ERROR
Definition: vumeter.h:156
vumeter_cfg_t::resolution
analog_in_resolution_t resolution
Definition: vumeter.h:144
vumeter_cfg_t::vref
float vref
Definition: vumeter.h:145
vumeter_t::chip_select
pin_name_t chip_select
Definition: vumeter.h:122
vumeter_calculate_vu_level
float vumeter_calculate_vu_level(vumeter_t *ctx, uint16_t sample_rate_ms)
VU Meter calculate VU level function.
vumeter_cfg_t::mosi
pin_name_t mosi
Definition: vumeter.h:134
vumeter_cfg_t::miso
pin_name_t miso
Definition: vumeter.h:133
vumeter_cfg_t::cs
pin_name_t cs
Definition: vumeter.h:136
vumeter_t::adc
analog_in_t adc
Definition: vumeter.h:120
vumeter_cfg_t::an
pin_name_t an
Definition: vumeter.h:137
vumeter_read_an_pin_voltage
err_t vumeter_read_an_pin_voltage(vumeter_t *ctx, float *data_out)
VU Meter read AN pin voltage level function.
vumeter_cfg_t
VU Meter Click configuration object.
Definition: vumeter.h:131
vumeter_set_gain_level
err_t vumeter_set_gain_level(vumeter_t *ctx, uint8_t gain_lvl)
VU Meter set gain level function.