audiodac 2.1.0.0
audiodac.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 AUDIODAC_H
29#define AUDIODAC_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 AUDIODAC_REG_P0_PAGE_SEL 0x00
74#define AUDIODAC_REG_P0_ANALOG_CTRL 0x01
75#define AUDIODAC_REG_P0_STBY_PDOWN 0x02
76#define AUDIODAC_REG_P0_MUTE 0x03
77#define AUDIODAC_REG_P0_PLL_LOCK_PLL_EN 0x04
78#define AUDIODAC_REG_P0_SPI_MISO_SEL 0x06
79#define AUDIODAC_REG_P0_DEEMP_EN_SDOUT_SEL 0x07
80#define AUDIODAC_REG_P0_GPIO_EN 0x08
81#define AUDIODAC_REG_P0_BCK_LRCLK 0x09
82#define AUDIODAC_REG_P0_DSP_GPIO_IN 0x0A
83#define AUDIODAC_REG_P0_M_BCK_LRCLK_RST 0x0C
84#define AUDIODAC_REG_P0_SREF 0x0D
85#define AUDIODAC_REG_P0_SDAC_CLK_SRC 0x0E
86#define AUDIODAC_REG_P0_GREF 0x12
87#define AUDIODAC_REG_P0_SYNC_REQ 0x13
88#define AUDIODAC_REG_P0_PLL_DIV_P 0x14
89#define AUDIODAC_REG_P0_PLL_DIV_J 0x15
90#define AUDIODAC_REG_P0_PLL_DIV_D_MSB 0x16
91#define AUDIODAC_REG_P0_PLL_DIV_D_LSB 0x17
92#define AUDIODAC_REG_P0_PLL_DIV_R 0x18
93#define AUDIODAC_REG_P0_DSP_CLK_DIV 0x1B
94#define AUDIODAC_REG_P0_DAC_CLK_DIV 0x1C
95#define AUDIODAC_REG_P0_NCP_CLK_DIV 0x1D
96#define AUDIODAC_REG_P0_OSR_CLK_DIV 0x1E
97#define AUDIODAC_REG_P0_M_MODE_BCK_DIV 0x20
98#define AUDIODAC_REG_P0_M_MODE_LRCK_DIV 0x21
99#define AUDIODAC_REG_P0_FS_SPEED_MODE 0x22
100#define AUDIODAC_REG_P0_IDAC_MSB 0x23
101#define AUDIODAC_REG_P0_IDAC_LSB 0x24
102#define AUDIODAC_REG_P0_IGNORE_ERRS 0x25
103#define AUDIODAC_REG_P0_I2S_DATA_FORMAT 0x28
104#define AUDIODAC_REG_P0_I2S_SHIFT 0x29
105#define AUDIODAC_REG_P0_DAC_DATA_PATH 0x2A
106#define AUDIODAC_REG_P0_DSP_PROGRAM_SEL 0x2B
107#define AUDIODAC_REG_P0_CLK_MISS_DET_PER 0x2C
108#define AUDIODAC_REG_P0_AUTO_MUTE_TIME 0x3B
109#define AUDIODAC_REG_P0_DIG_VOLUME_CTRL 0x3C
110#define AUDIODAC_REG_P0_DIG_VOLUME_LEFT 0x3D
111#define AUDIODAC_REG_P0_DIG_VOLUME_RIGHT 0x3E
112#define AUDIODAC_REG_P0_DIG_VOLUME_N_RU_RD 0x3F
113#define AUDIODAC_REG_P0_DIG_VOLUME_E_RU_RD 0x40
114#define AUDIODAC_REG_P0_AUTO_MUTE 0x41
115#define AUDIODAC_REG_P0_GPIO1_OUT_SEL 0x50
116#define AUDIODAC_REG_P0_GPIO2_OUT_SEL 0x51
117#define AUDIODAC_REG_P0_GPIO3_OUT_SEL 0x52
118#define AUDIODAC_REG_P0_GPIO4_OUT_SEL 0x53
119#define AUDIODAC_REG_P0_GPIO5_OUT_SEL 0x54
120#define AUDIODAC_REG_P0_GPIO6_OUT_SEL 0x55
121#define AUDIODAC_REG_P0_GPIO_CTRL 0x56
122#define AUDIODAC_REG_P0_GPIO_INV 0x57
123#define AUDIODAC_REG_P0_DSP_OVERFLOW 0x5A
124#define AUDIODAC_REG_P0_STAT_FS_SCK 0x5B
125#define AUDIODAC_REG_P0_STAT_BCK_MSB 0x5C
126#define AUDIODAC_REG_P0_STAT_BCK_LSB 0x5D
127#define AUDIODAC_REG_P0_STAT_1 0x5E
128#define AUDIODAC_REG_P0_STAT_2 0x5F
129#define AUDIODAC_REG_P0_MON_ANALOG_MUTE 0x6C
130#define AUDIODAC_REG_P0_MON_SHORT_DET 0x6D
131#define AUDIODAC_REG_P0_MON_MUTE 0x72
132#define AUDIODAC_REG_P0_MON_FS_SPEED_MODE 0x73
133#define AUDIODAC_REG_P0_MON_POWER_STATE 0x76
134#define AUDIODAC_REG_P0_GPIO_IN 0x77
135#define AUDIODAC_REG_P0_AUTO_MUTE_FLAGS 0x78
136#define AUDIODAC_REG_P0_DAC_MODE 0x79
137#define AUDIODAC_REG_P0_EXT_INTP_FILT 0x7A
138#define AUDIODAC_REG_P0_GP12_EXT_INTP_FILT 0x7B
139#define AUDIODAC_REG_P0_GP34_EXT_INTP_FILT 0x7C
140#define AUDIODAC_REG_P0_GP56_EXT_INTP_FILT 0x7D
141#define AUDIODAC_REG_P1_OUT_AMP_TYPE 0x01
142#define AUDIODAC_REG_P1_ANALOG_GAIN_CTRL 0x02
143#define AUDIODAC_REG_P1_UV_PROTECT 0x05
144#define AUDIODAC_REG_P1_ANALOG_MUTE_CTRL 0x06
145#define AUDIODAC_REG_P1_ANALOG_GAIN_BOOST 0x07
146#define AUDIODAC_REG_P1_VCOM_REF 0x08
147#define AUDIODAC_REG_P1_VCOM_PD_CTRL 0x09
148#define AUDIODAC_REG_P44_COEF_MEM_CTRL 0x01
149#define AUDIODAC_REG_P44_P52_COEF_BUF_A 0x2C
150#define AUDIODAC_REG_P62_P70_COEF_BUF_B 0x3E
151#define AUDIODAC_REG_P152_P186_INS_BUF 0x98
152#define AUDIODAC_REG_P253_CLK_FLEX_1_MODE 0x3F
153#define AUDIODAC_REG_P253_CLK_FLEX_2_MODE 0x40
154
155 // audiodac_reg
156
171#define AUDIODAC_AUTO_INCREMENT_ENABLE 0x80
172
177#define AUDIODAC_PAGE_0 0
178#define AUDIODAC_PAGE_1 1
179#define AUDIODAC_PAGE_44 44
180#define AUDIODAC_PAGE_62 62
181#define AUDIODAC_PAGE_152 152
182#define AUDIODAC_PAGE_253 253
183
188#define AUDIODAC_GPIO6_OUT_EN 0x20
189#define AUDIODAC_GPIO5_OUT_EN 0x10
190#define AUDIODAC_GPIO4_OUT_EN 0x08
191#define AUDIODAC_GPIO3_OUT_EN 0x04
192#define AUDIODAC_GPIO2_OUT_EN 0x02
193#define AUDIODAC_GPIO1_OUT_EN 0x01
194
199#define AUDIODAC_GPIO_OUT_SEL_OFF 0x00
200#define AUDIODAC_GPIO_OUT_SEL_DSP 0x01
201#define AUDIODAC_GPIO_OUT_SEL_REG_GPIO_OUT 0x02
202#define AUDIODAC_GPIO_OUT_SEL_AUTO_MUTE_LR 0x03
203#define AUDIODAC_GPIO_OUT_SEL_AUTO_MUTE_L 0x04
204#define AUDIODAC_GPIO_OUT_SEL_AUTO_MUTE_R 0x05
205#define AUDIODAC_GPIO_OUT_SEL_CLOCK_INVALID 0x06
206#define AUDIODAC_GPIO_OUT_SEL_SDOUT 0x07
207#define AUDIODAC_GPIO_OUT_SEL_AN_MUTE_L 0x08
208#define AUDIODAC_GPIO_OUT_SEL_AN_MUTE_R 0x09
209#define AUDIODAC_GPIO_OUT_SEL_PLL_LOCK 0x0A
210#define AUDIODAC_GPIO_OUT_SEL_UV_0_7_DVDD 0x0E
211#define AUDIODAC_GPIO_OUT_SEL_UV_0_3_DVDD 0x0F
212#define AUDIODAC_GPIO_OUT_SEL_PLL_OUT_DIV_4 0x10
213
218#define AUDIODAC_DIG_VOLUME_POS_MAX 0x00
219#define AUDIODAC_DIG_VOLUME_NO_ATT 0x30
220#define AUDIODAC_DIG_VOLUME_NEG_MIN 0xFE
221#define AUDIODAC_DIG_VOLUME_MUTE 0xFF
222
227#define AUDIODAC_VOLUME_MAX 100
228#define AUDIODAC_VOLUME_DEFAULT 48
229#define AUDIODAC_VOLUME_MIN 1
230#define AUDIODAC_VOLUME_MUTE 0
231
236#define AUDIODAC_CHANNEL_BOTH 0
237#define AUDIODAC_CHANNEL_LEFT 1
238#define AUDIODAC_CHANNEL_RIGHT 2
239
245#define AUDIODAC_DEVICE_ADDRESS 0x4C
246
247 // audiodac_set
248
263#define AUDIODAC_MAP_MIKROBUS( cfg, mikrobus ) \
264 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
265 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
266 cfg.mute = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
267 cfg.gpio4 = MIKROBUS( mikrobus, MIKROBUS_INT )
268
269 // audiodac_map
270 // audiodac
271
276typedef struct
277{
278 // Output pins
279 digital_out_t mute;
281 // Input pins
282 digital_in_t gpio4;
284 // Modules
285 i2c_master_t i2c;
287 // I2C slave address
290} audiodac_t;
291
296typedef struct
297{
298 pin_name_t scl;
299 pin_name_t sda;
301 pin_name_t mute;
302 pin_name_t gpio4;
304 uint32_t i2c_speed;
305 uint8_t i2c_address;
308
313typedef enum
314{
316 AUDIODAC_ERROR = -1
317
319
336
351
365
380err_t audiodac_generic_write ( audiodac_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
381
396err_t audiodac_generic_read ( audiodac_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
397
410err_t audiodac_write_register ( audiodac_t *ctx, uint8_t reg, uint8_t data_in );
411
424err_t audiodac_read_register ( audiodac_t *ctx, uint8_t reg, uint8_t *data_out );
425
435
445
456
468err_t audiodac_select_page ( audiodac_t *ctx, uint8_t page_num );
469
484err_t audiodac_volume_control ( audiodac_t *ctx, uint8_t channel, uint8_t volume );
485
486#ifdef __cplusplus
487}
488#endif
489#endif // AUDIODAC_H
490
491 // audiodac
492
493// ------------------------------------------------------------------------ END
audiodac_return_value_t
Audio DAC Click return value data.
Definition audiodac.h:314
@ AUDIODAC_ERROR
Definition audiodac.h:316
@ AUDIODAC_OK
Definition audiodac.h:315
err_t audiodac_generic_write(audiodac_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Audio DAC I2C writing function.
err_t audiodac_read_register(audiodac_t *ctx, uint8_t reg, uint8_t *data_out)
Audio DAC read register function.
void audiodac_cfg_setup(audiodac_cfg_t *cfg)
Audio DAC configuration object setup function.
err_t audiodac_select_page(audiodac_t *ctx, uint8_t page_num)
Audio DAC select page function.
uint8_t audiodac_get_gpio4_pin(audiodac_t *ctx)
Audio DAC get gpio4 pin function.
err_t audiodac_write_register(audiodac_t *ctx, uint8_t reg, uint8_t data_in)
Audio DAC write register function.
err_t audiodac_generic_read(audiodac_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Audio DAC I2C reading function.
void audiodac_unmute_output(audiodac_t *ctx)
Audio DAC unmute output function.
err_t audiodac_volume_control(audiodac_t *ctx, uint8_t channel, uint8_t volume)
Audio DAC volume control function.
err_t audiodac_init(audiodac_t *ctx, audiodac_cfg_t *cfg)
Audio DAC initialization function.
err_t audiodac_default_cfg(audiodac_t *ctx)
Audio DAC default configuration function.
void audiodac_mute_output(audiodac_t *ctx)
Audio DAC mute output function.
Audio DAC Click configuration object.
Definition audiodac.h:297
uint32_t i2c_speed
Definition audiodac.h:304
pin_name_t gpio4
Definition audiodac.h:302
pin_name_t scl
Definition audiodac.h:298
pin_name_t sda
Definition audiodac.h:299
pin_name_t mute
Definition audiodac.h:301
uint8_t i2c_address
Definition audiodac.h:305
Audio DAC Click context object.
Definition audiodac.h:277
digital_out_t mute
Definition audiodac.h:279
i2c_master_t i2c
Definition audiodac.h:285
digital_in_t gpio4
Definition audiodac.h:282
uint8_t slave_address
Definition audiodac.h:288