volume2 2.0.0.0
volume2.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 VOLUME2_H
29#define VOLUME2_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_i2c_master.h"
52
73#define VOLUME2_REG_VOLUME_1A_2A 0x00
74
79#define VOLUME2_REG_VOLUME_1B_ZERO1 0x01
80
85#define VOLUME2_REG_VOLUME_2B_ZERO2 0x02
86
87 // volume2_reg
88
103#define VOLUME2_GAIN_OPT_0_DB 0x00
104
109#define VOLUME2_GAIN_OPT_3_DB 0x01
110
115#define VOLUME2_GAIN_OPT_6_DB 0x02
116
121#define VOLUME2_GAIN_OPT_9_DB 0x03
122
127#define VOLUME2_ZERO_CROSS_DET_OPT_OFF 0x00
128
133#define VOLUME2_ZERO_CROSS_DET_OPT_ON 0x01
134
140#define VOLUME2_SET_DEV_ADDR 0x44
141
142 // volume2_set
143
158#define VOLUME2_DEVICE_MUTE_ON 0x00
159
164#define VOLUME2_DEVICE_MUTE_OFF 0x01
165
166 // mte_state
167
182#define VOLUME2_MAP_MIKROBUS( cfg, mikrobus ) \
183 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
184 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
185 cfg.mte = MIKROBUS( mikrobus, MIKROBUS_PWM )
186
187 // volume2_map
188 // volume2
189
194typedef struct
195{
196 // Output pins
197
198 digital_out_t mte;
200 // Modules
201
202 i2c_master_t i2c;
204 // I2C slave address
205
208} volume2_t;
209
214typedef struct
215{
216 pin_name_t scl;
217 pin_name_t sda;
219 pin_name_t mte;
221 uint32_t i2c_speed;
222 uint8_t i2c_address;
225
230typedef enum
231{
233 VOLUME2_ERROR = -1
234
236
241typedef struct
242{
243 uint8_t gain_ch1;
244 uint8_t gain_ch2;
251
270
288
305
323err_t volume2_generic_write ( volume2_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
324
342err_t volume2_generic_read ( volume2_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
343
358err_t volume2_device_mute ( volume2_t *ctx, uint8_t mte_state );
359
377
378#ifdef __cplusplus
379}
380#endif
381#endif // VOLUME2_H
382
383 // volume2
384
385// ------------------------------------------------------------------------ END
err_t volume2_device_mute(volume2_t *ctx, uint8_t mte_state)
Volume 2 device mute function.
err_t volume2_init(volume2_t *ctx, volume2_cfg_t *cfg)
Volume 2 initialization function.
err_t volume2_generic_write(volume2_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Volume 2 I2C writing function.
err_t volume2_update_vol_data(volume2_t *ctx, volume2_vol_data_t update_data)
Volume 2 update volume data function.
void volume2_cfg_setup(volume2_cfg_t *cfg)
Volume 2 configuration object setup function.
err_t volume2_default_cfg(volume2_t *ctx)
Volume 2 default configuration function.
err_t volume2_generic_read(volume2_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Volume 2 I2C reading function.
Volume 2 Click configuration object.
Definition volume2.h:215
pin_name_t mte
Definition volume2.h:219
uint32_t i2c_speed
Definition volume2.h:221
pin_name_t scl
Definition volume2.h:216
pin_name_t sda
Definition volume2.h:217
uint8_t i2c_address
Definition volume2.h:222
Volume 2 Click context object.
Definition volume2.h:195
digital_out_t mte
Definition volume2.h:198
i2c_master_t i2c
Definition volume2.h:202
uint8_t slave_address
Definition volume2.h:206
Volume 2 Vol data structure.
Definition volume2.h:242
uint8_t gain_ch2
Definition volume2.h:244
uint8_t attenuation_ch1
Definition volume2.h:245
uint8_t zero_cross_det_ch2
Definition volume2.h:248
uint8_t attenuation_ch2
Definition volume2.h:246
uint8_t gain_ch1
Definition volume2.h:243
uint8_t zero_cross_det_ch1
Definition volume2.h:247
volume2_return_value_t
Volume 2 Click return value data.
Definition volume2.h:231
@ VOLUME2_ERROR
Definition volume2.h:233
@ VOLUME2_OK
Definition volume2.h:232