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 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_spi_master.h"
47 
64 #define VOLUME_ZCE_DISABLE 0x00
65 #define VOLUME_ZCE_ENABLE 0x01
66  // zce_state
68 
79 #define VOLUME_MUTE_ENABLE 0x00
80 #define VOLUME_MUTE_DISABLE 0x01
81  // mute_state
83 
84 
99 #define VOLUME_MAP_MIKROBUS( cfg, mikrobus ) \
100  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
101  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
102  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
103  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
104  cfg.zce = MIKROBUS( mikrobus, MIKROBUS_AN ); \
105  cfg.sen = MIKROBUS( mikrobus, MIKROBUS_PWM )
106  // volume_map // volume
109 
114 typedef struct
115 {
116  // Output pins
117 
118  digital_out_t zce;
119  digital_out_t sen;
121  // Modules
122 
123  spi_master_t spi;
125  pin_name_t chip_select;
127 } volume_t;
128 
133 typedef struct
134 {
135  // Communication gpio pins
136 
137  pin_name_t miso;
138  pin_name_t mosi;
139  pin_name_t sck;
140  pin_name_t cs;
142  // Additional gpio pins
143 
144  pin_name_t zce;
145  pin_name_t sen;
147  // static variable
148 
149  uint32_t spi_speed;
150  spi_master_mode_t spi_mode;
151  spi_master_chip_select_polarity_t cs_polarity;
153 } volume_cfg_t;
154 
171 
186 err_t volume_init ( volume_t *ctx, volume_cfg_t *cfg );
187 
199 
209 void volume_power_up ( volume_t *ctx );
210 
221 void volume_hw_mute ( volume_t *ctx, uint8_t mute_state );
222 
233 void volume_zero_crossing ( volume_t *ctx, uint8_t zce_state );
234 
247 err_t volume_set_vol_gain ( volume_t *ctx, float volume_left_dB, float volume_right_dB );
248 
249 #ifdef __cplusplus
250 }
251 #endif
252 #endif // VOLUME_H
253  // volume
255 
256 // ------------------------------------------------------------------------ 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:149
volume_t::zce
digital_out_t zce
Definition: volume.h:118
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:125
volume_t
Volume Click context object.
Definition: volume.h:115
volume_cfg_t::mosi
pin_name_t mosi
Definition: volume.h:138
volume_cfg_t::miso
pin_name_t miso
Definition: volume.h:137
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:119
volume_cfg_t::zce
pin_name_t zce
Definition: volume.h:144
volume_cfg_t::sen
pin_name_t sen
Definition: volume.h:145
volume_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: volume.h:151
volume_cfg_t::sck
pin_name_t sck
Definition: volume.h:139
volume_cfg_t::cs
pin_name_t cs
Definition: volume.h:140
volume_cfg_t
Volume Click configuration object.
Definition: volume.h:134
volume_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: volume.h:150
volume_t::spi
spi_master_t spi
Definition: volume.h:123
volume_init
err_t volume_init(volume_t *ctx, volume_cfg_t *cfg)
Volume initialization function.