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_MIN_VU -20.0
73 #define VUMETER_VCC_3V3 3.3
74 #define VUMETER_VCC_5V 5.0
75 
84 #define VUMETER_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
85 #define VUMETER_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
86  // vumeter_set
88 
103 #define VUMETER_MAP_MIKROBUS( cfg, mikrobus ) \
104  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
105  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
106  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
107  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
108  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN )
109  // vumeter_map // vumeter
112 
117 typedef struct
118 {
119  // Modules
120  spi_master_t spi;
121  analog_in_t adc;
123  pin_name_t chip_select;
125 } vumeter_t;
126 
131 typedef struct
132 {
133  // Communication gpio pins
134  pin_name_t miso;
135  pin_name_t mosi;
136  pin_name_t sck;
137  pin_name_t cs;
138  pin_name_t an;
140  // static variable
141  uint32_t spi_speed;
142  spi_master_mode_t spi_mode;
143  spi_master_chip_select_polarity_t cs_polarity;
145  analog_in_resolution_t resolution;
146  float vref;
148 } vumeter_cfg_t;
149 
154 typedef enum
155 {
157  VUMETER_ERROR = -1
158 
160 
177 
192 err_t vumeter_init ( vumeter_t *ctx, vumeter_cfg_t *cfg );
193 
206 err_t vumeter_read_an_pin_value ( vumeter_t *ctx, uint16_t *data_out );
207 
222 err_t vumeter_read_an_pin_voltage ( vumeter_t *ctx, float *data_out );
223 
236 err_t vumeter_set_gain_level ( vumeter_t *ctx, uint8_t gain_lvl );
237 
249 float vumeter_calculate_vu_level ( vumeter_t *ctx, uint16_t sample_rate_ms );
250 
251 #ifdef __cplusplus
252 }
253 #endif
254 #endif // VUMETER_H
255  // vumeter
257 
258 // ------------------------------------------------------------------------ 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:142
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:120
vumeter_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: vumeter.h:143
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:155
VUMETER_OK
@ VUMETER_OK
Definition: vumeter.h:156
vumeter_t
VU Meter Click context object.
Definition: vumeter.h:118
vumeter_cfg_t::sck
pin_name_t sck
Definition: vumeter.h:136
vumeter_cfg_t::spi_speed
uint32_t spi_speed
Definition: vumeter.h:141
VUMETER_ERROR
@ VUMETER_ERROR
Definition: vumeter.h:157
vumeter_cfg_t::resolution
analog_in_resolution_t resolution
Definition: vumeter.h:145
vumeter_cfg_t::vref
float vref
Definition: vumeter.h:146
vumeter_t::chip_select
pin_name_t chip_select
Definition: vumeter.h:123
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:135
vumeter_cfg_t::miso
pin_name_t miso
Definition: vumeter.h:134
vumeter_cfg_t::cs
pin_name_t cs
Definition: vumeter.h:137
vumeter_t::adc
analog_in_t adc
Definition: vumeter.h:121
vumeter_cfg_t::an
pin_name_t an
Definition: vumeter.h:138
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:132
vumeter_set_gain_level
err_t vumeter_set_gain_level(vumeter_t *ctx, uint8_t gain_lvl)
VU Meter set gain level function.