audiomux 2.0.0.0
audiomux.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef AUDIOMUX_H
36#define AUDIOMUX_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56
57// -------------------------------------------------------------- PUBLIC MACROS
67#define AUDIOMUX_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
78#define AUDIOMUX_RETVAL uint8_t
79
80#define AUDIOMUX_OK 0x00
81#define AUDIOMUX_INIT_ERROR 0xFF
88#define AUDIOMUX_DEVICE_ADDR 0x44
95#define AUDIOMUX_AUTO_INCR 0x10
102#define AUDIOMUX_INPUT_SEL_ADDR 0x00
103#define AUDIOMUX_INPUT_GAIN_ADDR 0x01
104#define AUDIOMUX_SURROUND_ADDR 0x02
105#define AUDIOMUX_VOLUME_LEFT_ADDR 0x03
106#define AUDIOMUX_VOLUME_RIGHT_ADDR 0x04
107#define AUDIOMUX_TREBLE_BASS_ADDR 0x05
108#define AUDIOMUX_OUTPUT_ADDR 0x06
109#define AUDIOMUX_BASS_ALC_ADDR 0x07
116#define AUDIOMUX_IN1_EN 0x00
117#define AUDIOMUX_IN2_EN 0x01
118#define AUDIOMUX_IN3_EN 0x02
119#define AUDIOMUX_IN4_EN 0x03
120#define AUDIOMUX_MIC_GAIN_14DB 0x00
121#define AUDIOMUX_MIC_GAIN_10DB 0x01
122#define AUDIOMUX_MIC_GAIN_6DB 0x02
123#define AUDIOMUX_MIC_GAIN_0DB 0x03
124#define AUDIOMUX_MIC_OFF 0x01
125#define AUDIOMUX_MIC_ON 0x00
132#define AUDIOMUX_MUTE_INPUT_ON 0x01
133#define AUDIOMUX_MUTE_INPUT_OFF 0x00
140#define AUDIOMUX_IN_GAIN_0DB 0x00
141#define AUDIOMUX_IN_GAIN_2DB 0x01
142#define AUDIOMUX_IN_GAIN_4DB 0x02
143#define AUDIOMUX_IN_GAIN_6DB 0x03
144#define AUDIOMUX_IN_GAIN_8DB 0x04
145#define AUDIOMUX_IN_GAIN_10DB 0x05
146#define AUDIOMUX_IN_GAIN_12DB 0x06
147#define AUDIOMUX_IN_GAIN_14DB 0x07
154#define AUDIOMUX_SURROUND_MODE_ON 0x01
155#define AUDIOMUX_SURROUND_MODE_OFF 0x00
156#define AUDIOMUX_SURROUND_GAIN_0DB 0x00
157#define AUDIOMUX_SURROUND_GAIN_6DB 0x02
158#define AUDIOMUX_SURROUND_GAIN_9DB 0x04
159#define AUDIOMUX_SURROUND_GAIN_12DB 0x06
160#define AUDIOMUX_MIX_INV_100 0x00
161#define AUDIOMUX_MIX_INV_50 0x08
162#define AUDIOMUX_MIX_INV_25 0x10
163#define AUDIOMUX_MIX_0 0x18
164#define AUDIOMUX_MIX_NONINV_100 0x20
165#define AUDIOMUX_MIX_NONINV_75 0x28
166#define AUDIOMUX_MIX_NONINV_50 0x30
167#define AUDIOMUX_MIX_MUTE 0x38
168#define AUDIOMUX_BUFF_GAIN_0 0x40
169#define AUDIOMUX_BUFF_GAIN_6DB 0x00
176#define AUDIOMUX_VOL1_0DB 0x00
177#define AUDIOMUX_VOL1_1DB_NEG 0x01
178#define AUDIOMUX_VOL1_2DB_NEG 0x02
179#define AUDIOMUX_VOL1_3DB_NEG 0x03
180#define AUDIOMUX_VOL1_4DB_NEG 0x04
181#define AUDIOMUX_VOL1_5DB_NEG 0x05
182#define AUDIOMUX_VOL1_6DB_NEG 0x06
183#define AUDIOMUX_VOL1_7DB_NEG 0x07
184#define AUDIOMUX_VOL1_8DB_NEG 0x08
185#define AUDIOMUX_VOL1_16DB_NEG 0x10
186#define AUDIOMUX_VOL1_24DB_NEG 0x18
187#define AUDIOMUX_VOL1_32DB_NEG 0x20
188#define AUDIOMUX_VOL1_40DB_NEG 0x28
189#define AUDIOMUX_VOL1_48DB_NEG 0x30
190#define AUDIOMUX_VOL1_56DB_NEG 0x38
191#define AUDIOMUX_VOL2_0DB 0x00
192#define AUDIOMUX_VOL2_8DB_NEG 0x01
193#define AUDIOMUX_VOL2_16DB_NEG 0x02
194#define AUDIOMUX_VOL2_24DB_NEG 0x03
201#define AUDIOMUX_TRE_BASS_14DB_NEG 0x00
202#define AUDIOMUX_TRE_BASS_12DB_NEG 0x01
203#define AUDIOMUX_TRE_BASS_10DB_NEG 0x02
204#define AUDIOMUX_TRE_BASS_8DB_NEG 0x03
205#define AUDIOMUX_TRE_BASS_6DB_NEG 0x04
206#define AUDIOMUX_TRE_BASS_4DB_NEG 0x05
207#define AUDIOMUX_TRE_BASS_2DB_NEG 0x06
208#define AUDIOMUX_TRE_BASS_0DB 0x07
209#define AUDIOMUX_TRE_BASS_14DB 0x08
210#define AUDIOMUX_TRE_BASS_12DB 0x09
211#define AUDIOMUX_TRE_BASS_10DB 0x0A
212#define AUDIOMUX_TRE_BASS_8DB 0x0B
213#define AUDIOMUX_TRE_BASS_6DB 0x0C
214#define AUDIOMUX_TRE_BASS_4DB 0x0D
215#define AUDIOMUX_TRE_BASS_2DB 0x0E
222#define AUDIOMUX_MUTE_OUTPUT_ON 0x00
223#define AUDIOMUX_MUTE_OUTPUT_OFF 0x01
230#define AUDIOMUX_ALC_MODE_ON 0x01
231#define AUDIOMUX_DETECTOR_ON 0x02
232#define AUDIOMUX_RELEASE_CURR 0x04
233#define AUDIOMUX_TIME_RES_12K5 0x00
234#define AUDIOMUX_TIME_RES_25K 0x08
235#define AUDIOMUX_TIME_RES_50K 0x10
236#define AUDIOMUX_TIME_RES_100K 0x18
237#define AUDIOMUX_THRSH_700MVRMS 0x00
238#define AUDIOMUX_THRSH_485MVRMS 0x20
239#define AUDIOMUX_THRSH_320MVRMS 0x40
240#define AUDIOMUX_THRSH_170MVRMS 0x60
241#define AUDIOMUX_MODE1_FIXED_RES 0x00
242#define AUDIOMUX_MODE2_ADAPTIVE 0x80
249#define AUDIOMUX_OK 0x00
250#define AUDIOMUX_ADDR_ERR 0x01
251#define AUDIOMUX_NBYTES_ERR 0x02
252#define AUDIOMUX_IN_SEL_ERR 0x03
253#define AUDIOMUX_GAIN_ERR 0x04
254#define AUDIOMUX_STATE_ERR 0x05
255#define AUDIOMUX_VOL_ERR 0x06
256#define AUDIOMUX_TRE_BASS_ERR 0x07
263#define T_AUDIOMUX_P const uint8_t*
264#define T_AUDIOMUX_RETVAL uint8_t
268 // End group macro
269// --------------------------------------------------------------- PUBLIC TYPES
278typedef struct
279{
280 // Modules
281
282 i2c_master_t i2c;
283
284 // ctx variable
285
287
288} audiomux_t;
289
293typedef struct
294{
295 // Communication gpio pins
296
297 pin_name_t scl;
298 pin_name_t sda;
299
300 // static variable
301
302 uint32_t i2c_speed;
303 uint8_t i2c_address;
304
306
307 // End types group
308// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
309
315#ifdef __cplusplus
316extern "C"{
317#endif
318
328
337
350
361void audiomux_generic_write ( audiomux_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
362
374void audiomux_generic_read ( audiomux_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
375
388 uint8_t data_in );
389
403 uint8_t *data_in, uint8_t n_bytes );
404
417 uint8_t *data_out );
418
432 uint8_t *data_out, uint8_t n_bytes );
433
447T_AUDIOMUX_RETVAL audiomux_select_input ( audiomux_t *ctx, uint8_t input_sel, uint8_t mute_in,
448 uint8_t mic_gain, uint8_t mic_state );
449
461
474T_AUDIOMUX_RETVAL audiomux_set_volume ( audiomux_t *ctx, uint8_t volume1, uint8_t volume2,
475 uint8_t side_sel );
476
488T_AUDIOMUX_RETVAL audiomux_set_treble_bass ( audiomux_t *ctx, uint8_t treble, uint8_t bass );
489
501
502
503#ifdef __cplusplus
504}
505#endif
506#endif // _AUDIOMUX_H_
507
508 // End public_function group
510
511// ------------------------------------------------------------------------- END
#define AUDIOMUX_RETVAL
Definition audiomux.h:78
#define T_AUDIOMUX_RETVAL
Definition audiomux.h:264
void audiomux_cfg_setup(audiomux_cfg_t *cfg)
Config Object Initialization function.
T_AUDIOMUX_RETVAL audiomux_read_single_byte(audiomux_t *ctx, uint8_t reg_addr, uint8_t *data_out)
Single Read function.
AUDIOMUX_RETVAL audiomux_init(audiomux_t *ctx, audiomux_cfg_t *cfg)
Initialization function.
T_AUDIOMUX_RETVAL audiomux_set_treble_bass(audiomux_t *ctx, uint8_t treble, uint8_t bass)
Treble and Bass Control function.
void audiomux_default_cfg(audiomux_t *ctx)
Click Default Configuration function.
T_AUDIOMUX_RETVAL audiomux_read_bytes(audiomux_t *ctx, uint8_t start_addr, uint8_t *data_out, uint8_t n_bytes)
Multiple Read function.
T_AUDIOMUX_RETVAL audiomux_set_volume(audiomux_t *ctx, uint8_t volume1, uint8_t volume2, uint8_t side_sel)
Volume Control function.
T_AUDIOMUX_RETVAL audiomux_write_bytes(audiomux_t *ctx, uint8_t start_addr, uint8_t *data_in, uint8_t n_bytes)
Multiple Write function.
T_AUDIOMUX_RETVAL audiomux_select_input(audiomux_t *ctx, uint8_t input_sel, uint8_t mute_in, uint8_t mic_gain, uint8_t mic_state)
Input Selection function.
T_AUDIOMUX_RETVAL audiomux_set_input_gain(audiomux_t *ctx, uint8_t input_gain)
Input Gain Control function.
void audiomux_generic_write(audiomux_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
T_AUDIOMUX_RETVAL audiomux_mute_ouput(audiomux_t *ctx, uint8_t state)
Output Mute function.
void audiomux_generic_read(audiomux_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
T_AUDIOMUX_RETVAL audiomux_write_single_byte(audiomux_t *ctx, uint8_t reg_addr, uint8_t data_in)
Single Write function.
Click configuration structure definition.
Definition audiomux.h:294
uint32_t i2c_speed
Definition audiomux.h:302
pin_name_t scl
Definition audiomux.h:297
pin_name_t sda
Definition audiomux.h:298
uint8_t i2c_address
Definition audiomux.h:303
Click ctx object definition.
Definition audiomux.h:279
i2c_master_t i2c
Definition audiomux.h:282
uint8_t slave_address
Definition audiomux.h:286