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
32extern "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 VUMETER_GAIN_LEVEL_MAX 0xFF
76#define VUMETER_GAIN_LEVEL_MID 0x80
77#define VUMETER_GAIN_LEVEL_MIN 0x00
78
83#define VUMETER_DBU_VREF 0.7746
84#define VUMETER_DBU_TO_VU 4.0
85#define VUMETER_RMS_FOR_20VU 0.123
86#define VUMETER_MIN_VU -20.0
87#define VUMETER_VCC_3V3 3.3
88#define VUMETER_VCC_5V 5.0
89
98#define VUMETER_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
99#define VUMETER_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
100
101 // vumeter_set
102
117#define VUMETER_MAP_MIKROBUS( cfg, mikrobus ) \
118 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
119 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
120 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
121 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
122 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN )
123
124 // vumeter_map
125 // vumeter
126
131typedef struct
132{
133 // Modules
134 spi_master_t spi;
135 analog_in_t adc;
137 pin_name_t chip_select;
139} vumeter_t;
140
145typedef struct
146{
147 // Communication gpio pins
148 pin_name_t miso;
149 pin_name_t mosi;
150 pin_name_t sck;
151 pin_name_t cs;
152 pin_name_t an;
154 // static variable
155 uint32_t spi_speed;
156 spi_master_mode_t spi_mode;
157 spi_master_chip_select_polarity_t cs_polarity;
159 analog_in_resolution_t resolution;
160 float vref;
163
168typedef enum
169{
171 VUMETER_ERROR = -1
172
174
191
207
220err_t vumeter_read_an_pin_value ( vumeter_t *ctx, uint16_t *data_out );
221
236err_t vumeter_read_an_pin_voltage ( vumeter_t *ctx, float *data_out );
237
250err_t vumeter_set_gain_level ( vumeter_t *ctx, uint8_t gain_lvl );
251
263float vumeter_calculate_vu_level ( vumeter_t *ctx, uint16_t sample_rate_ms );
264
265#ifdef __cplusplus
266}
267#endif
268#endif // VUMETER_H
269
270 // vumeter
271
272// ------------------------------------------------------------------------ END
err_t vumeter_init(vumeter_t *ctx, vumeter_cfg_t *cfg)
VU Meter initialization function.
err_t vumeter_read_an_pin_voltage(vumeter_t *ctx, float *data_out)
VU Meter read AN pin voltage level function.
err_t vumeter_read_an_pin_value(vumeter_t *ctx, uint16_t *data_out)
VU Meter read AN pin value function.
float vumeter_calculate_vu_level(vumeter_t *ctx, uint16_t sample_rate_ms)
VU Meter calculate VU level function.
void vumeter_cfg_setup(vumeter_cfg_t *cfg)
VU Meter configuration object setup function.
err_t vumeter_set_gain_level(vumeter_t *ctx, uint8_t gain_lvl)
VU Meter set gain level function.
This file contains SPI specific macros, functions, etc.
VU Meter Click configuration object.
Definition vumeter.h:146
analog_in_resolution_t resolution
Definition vumeter.h:159
float vref
Definition vumeter.h:160
spi_master_chip_select_polarity_t cs_polarity
Definition vumeter.h:157
pin_name_t sck
Definition vumeter.h:150
spi_master_mode_t spi_mode
Definition vumeter.h:156
pin_name_t mosi
Definition vumeter.h:149
uint32_t spi_speed
Definition vumeter.h:155
pin_name_t miso
Definition vumeter.h:148
pin_name_t an
Definition vumeter.h:152
pin_name_t cs
Definition vumeter.h:151
VU Meter Click context object.
Definition vumeter.h:132
spi_master_t spi
Definition vumeter.h:134
pin_name_t chip_select
Definition vumeter.h:137
analog_in_t adc
Definition vumeter.h:135
vumeter_return_value_t
VU Meter Click return value data.
Definition vumeter.h:169
@ VUMETER_ERROR
Definition vumeter.h:171
@ VUMETER_OK
Definition vumeter.h:170