volume  2.0.0.0
volume.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 VOLUME_H
29 #define VOLUME_H
30 
31 #ifdef __cplusplus
32 extern "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_spi_master.h"
51 
68 #define VOLUME_ZCE_DISABLE 0x00
69 #define VOLUME_ZCE_ENABLE 0x01
70  // zce_state
72 
83 #define VOLUME_MUTE_ENABLE 0x00
84 #define VOLUME_MUTE_DISABLE 0x01
85  // mute_state
87 
88 
103 #define VOLUME_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.zce = MIKROBUS( mikrobus, MIKROBUS_AN ); \
109  cfg.sen = MIKROBUS( mikrobus, MIKROBUS_PWM )
110  // volume_map // volume
113 
118 typedef struct
119 {
120  // Output pins
121 
122  digital_out_t zce;
123  digital_out_t sen;
125  // Modules
126 
127  spi_master_t spi;
129  pin_name_t chip_select;
131 } volume_t;
132 
137 typedef struct
138 {
139  // Communication gpio pins
140 
141  pin_name_t miso;
142  pin_name_t mosi;
143  pin_name_t sck;
144  pin_name_t cs;
146  // Additional gpio pins
147 
148  pin_name_t zce;
149  pin_name_t sen;
151  // static variable
152 
153  uint32_t spi_speed;
154  spi_master_mode_t spi_mode;
155  spi_master_chip_select_polarity_t cs_polarity;
157 } volume_cfg_t;
158 
175 
190 err_t volume_init ( volume_t *ctx, volume_cfg_t *cfg );
191 
203 
213 void volume_power_up ( volume_t *ctx );
214 
225 void volume_hw_mute ( volume_t *ctx, uint8_t mute_state );
226 
237 void volume_zero_crossing ( volume_t *ctx, uint8_t zce_state );
238 
251 err_t volume_set_vol_gain ( volume_t *ctx, float volume_left_dB, float volume_right_dB );
252 
253 #ifdef __cplusplus
254 }
255 #endif
256 #endif // VOLUME_H
257  // volume
259 
260 // ------------------------------------------------------------------------ END
volume_power_up
void volume_power_up(volume_t *ctx)
Power Up function.
volume_zero_crossing
void volume_zero_crossing(volume_t *ctx, uint8_t zce_state)
Zero Crossing option function.
volume_cfg_t::spi_speed
uint32_t spi_speed
Definition: volume.h:153
volume_t::zce
digital_out_t zce
Definition: volume.h:122
volume_set_vol_gain
err_t volume_set_vol_gain(volume_t *ctx, float volume_left_dB, float volume_right_dB)
Set volume gain function.
volume_default_cfg
void volume_default_cfg(volume_t *ctx)
Volume default configuration function.
volume_t::chip_select
pin_name_t chip_select
Definition: volume.h:129
volume_t
Volume Click context object.
Definition: volume.h:119
volume_cfg_t::mosi
pin_name_t mosi
Definition: volume.h:142
volume_cfg_t::miso
pin_name_t miso
Definition: volume.h:141
volume_cfg_setup
void volume_cfg_setup(volume_cfg_t *cfg)
Volume configuration object setup function.
volume_hw_mute
void volume_hw_mute(volume_t *ctx, uint8_t mute_state)
Hardware MUTE function.
volume_t::sen
digital_out_t sen
Definition: volume.h:123
volume_cfg_t::zce
pin_name_t zce
Definition: volume.h:148
volume_cfg_t::sen
pin_name_t sen
Definition: volume.h:149
volume_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: volume.h:155
volume_cfg_t::sck
pin_name_t sck
Definition: volume.h:143
volume_cfg_t::cs
pin_name_t cs
Definition: volume.h:144
volume_cfg_t
Volume Click configuration object.
Definition: volume.h:138
volume_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: volume.h:154
volume_t::spi
spi_master_t spi
Definition: volume.h:127
volume_init
err_t volume_init(volume_t *ctx, volume_cfg_t *cfg)
Volume initialization function.