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
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_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define AUDIODAC_REG_P0_PAGE_SEL 0x00
70 #define AUDIODAC_REG_P0_ANALOG_CTRL 0x01
71 #define AUDIODAC_REG_P0_STBY_PDOWN 0x02
72 #define AUDIODAC_REG_P0_MUTE 0x03
73 #define AUDIODAC_REG_P0_PLL_LOCK_PLL_EN 0x04
74 #define AUDIODAC_REG_P0_SPI_MISO_SEL 0x06
75 #define AUDIODAC_REG_P0_DEEMP_EN_SDOUT_SEL 0x07
76 #define AUDIODAC_REG_P0_GPIO_EN 0x08
77 #define AUDIODAC_REG_P0_BCK_LRCLK 0x09
78 #define AUDIODAC_REG_P0_DSP_GPIO_IN 0x0A
79 #define AUDIODAC_REG_P0_M_BCK_LRCLK_RST 0x0C
80 #define AUDIODAC_REG_P0_SREF 0x0D
81 #define AUDIODAC_REG_P0_SDAC_CLK_SRC 0x0E
82 #define AUDIODAC_REG_P0_GREF 0x12
83 #define AUDIODAC_REG_P0_SYNC_REQ 0x13
84 #define AUDIODAC_REG_P0_PLL_DIV_P 0x14
85 #define AUDIODAC_REG_P0_PLL_DIV_J 0x15
86 #define AUDIODAC_REG_P0_PLL_DIV_D_MSB 0x16
87 #define AUDIODAC_REG_P0_PLL_DIV_D_LSB 0x17
88 #define AUDIODAC_REG_P0_PLL_DIV_R 0x18
89 #define AUDIODAC_REG_P0_DSP_CLK_DIV 0x1B
90 #define AUDIODAC_REG_P0_DAC_CLK_DIV 0x1C
91 #define AUDIODAC_REG_P0_NCP_CLK_DIV 0x1D
92 #define AUDIODAC_REG_P0_OSR_CLK_DIV 0x1E
93 #define AUDIODAC_REG_P0_M_MODE_BCK_DIV 0x20
94 #define AUDIODAC_REG_P0_M_MODE_LRCK_DIV 0x21
95 #define AUDIODAC_REG_P0_FS_SPEED_MODE 0x22
96 #define AUDIODAC_REG_P0_IDAC_MSB 0x23
97 #define AUDIODAC_REG_P0_IDAC_LSB 0x24
98 #define AUDIODAC_REG_P0_IGNORE_ERRS 0x25
99 #define AUDIODAC_REG_P0_I2S_DATA_FORMAT 0x28
100 #define AUDIODAC_REG_P0_I2S_SHIFT 0x29
101 #define AUDIODAC_REG_P0_DAC_DATA_PATH 0x2A
102 #define AUDIODAC_REG_P0_DSP_PROGRAM_SEL 0x2B
103 #define AUDIODAC_REG_P0_CLK_MISS_DET_PER 0x2C
104 #define AUDIODAC_REG_P0_AUTO_MUTE_TIME 0x3B
105 #define AUDIODAC_REG_P0_DIG_VOLUME_CTRL 0x3C
106 #define AUDIODAC_REG_P0_DIG_VOLUME_LEFT 0x3D
107 #define AUDIODAC_REG_P0_DIG_VOLUME_RIGHT 0x3E
108 #define AUDIODAC_REG_P0_DIG_VOLUME_N_RU_RD 0x3F
109 #define AUDIODAC_REG_P0_DIG_VOLUME_E_RU_RD 0x40
110 #define AUDIODAC_REG_P0_AUTO_MUTE 0x41
111 #define AUDIODAC_REG_P0_GPIO1_OUT_SEL 0x50
112 #define AUDIODAC_REG_P0_GPIO2_OUT_SEL 0x51
113 #define AUDIODAC_REG_P0_GPIO3_OUT_SEL 0x52
114 #define AUDIODAC_REG_P0_GPIO4_OUT_SEL 0x53
115 #define AUDIODAC_REG_P0_GPIO5_OUT_SEL 0x54
116 #define AUDIODAC_REG_P0_GPIO6_OUT_SEL 0x55
117 #define AUDIODAC_REG_P0_GPIO_CTRL 0x56
118 #define AUDIODAC_REG_P0_GPIO_INV 0x57
119 #define AUDIODAC_REG_P0_DSP_OVERFLOW 0x5A
120 #define AUDIODAC_REG_P0_STAT_FS_SCK 0x5B
121 #define AUDIODAC_REG_P0_STAT_BCK_MSB 0x5C
122 #define AUDIODAC_REG_P0_STAT_BCK_LSB 0x5D
123 #define AUDIODAC_REG_P0_STAT_1 0x5E
124 #define AUDIODAC_REG_P0_STAT_2 0x5F
125 #define AUDIODAC_REG_P0_MON_ANALOG_MUTE 0x6C
126 #define AUDIODAC_REG_P0_MON_SHORT_DET 0x6D
127 #define AUDIODAC_REG_P0_MON_MUTE 0x72
128 #define AUDIODAC_REG_P0_MON_FS_SPEED_MODE 0x73
129 #define AUDIODAC_REG_P0_MON_POWER_STATE 0x76
130 #define AUDIODAC_REG_P0_GPIO_IN 0x77
131 #define AUDIODAC_REG_P0_AUTO_MUTE_FLAGS 0x78
132 #define AUDIODAC_REG_P0_DAC_MODE 0x79
133 #define AUDIODAC_REG_P0_EXT_INTP_FILT 0x7A
134 #define AUDIODAC_REG_P0_GP12_EXT_INTP_FILT 0x7B
135 #define AUDIODAC_REG_P0_GP34_EXT_INTP_FILT 0x7C
136 #define AUDIODAC_REG_P0_GP56_EXT_INTP_FILT 0x7D
137 #define AUDIODAC_REG_P1_OUT_AMP_TYPE 0x01
138 #define AUDIODAC_REG_P1_ANALOG_GAIN_CTRL 0x02
139 #define AUDIODAC_REG_P1_UV_PROTECT 0x05
140 #define AUDIODAC_REG_P1_ANALOG_MUTE_CTRL 0x06
141 #define AUDIODAC_REG_P1_ANALOG_GAIN_BOOST 0x07
142 #define AUDIODAC_REG_P1_VCOM_REF 0x08
143 #define AUDIODAC_REG_P1_VCOM_PD_CTRL 0x09
144 #define AUDIODAC_REG_P44_COEF_MEM_CTRL 0x01
145 #define AUDIODAC_REG_P44_P52_COEF_BUF_A 0x2C
146 #define AUDIODAC_REG_P62_P70_COEF_BUF_B 0x3E
147 #define AUDIODAC_REG_P152_P186_INS_BUF 0x98
148 #define AUDIODAC_REG_P253_CLK_FLEX_1_MODE 0x3F
149 #define AUDIODAC_REG_P253_CLK_FLEX_2_MODE 0x40
150  // audiodac_reg
152 
167 #define AUDIODAC_AUTO_INCREMENT_ENABLE 0x80
168 
173 #define AUDIODAC_PAGE_0 0
174 #define AUDIODAC_PAGE_1 1
175 #define AUDIODAC_PAGE_44 44
176 #define AUDIODAC_PAGE_62 62
177 #define AUDIODAC_PAGE_152 152
178 #define AUDIODAC_PAGE_253 253
179 
184 #define AUDIODAC_GPIO6_OUT_EN 0x20
185 #define AUDIODAC_GPIO5_OUT_EN 0x10
186 #define AUDIODAC_GPIO4_OUT_EN 0x08
187 #define AUDIODAC_GPIO3_OUT_EN 0x04
188 #define AUDIODAC_GPIO2_OUT_EN 0x02
189 #define AUDIODAC_GPIO1_OUT_EN 0x01
190 
195 #define AUDIODAC_GPIO_OUT_SEL_OFF 0x00
196 #define AUDIODAC_GPIO_OUT_SEL_DSP 0x01
197 #define AUDIODAC_GPIO_OUT_SEL_REG_GPIO_OUT 0x02
198 #define AUDIODAC_GPIO_OUT_SEL_AUTO_MUTE_LR 0x03
199 #define AUDIODAC_GPIO_OUT_SEL_AUTO_MUTE_L 0x04
200 #define AUDIODAC_GPIO_OUT_SEL_AUTO_MUTE_R 0x05
201 #define AUDIODAC_GPIO_OUT_SEL_CLOCK_INVALID 0x06
202 #define AUDIODAC_GPIO_OUT_SEL_SDOUT 0x07
203 #define AUDIODAC_GPIO_OUT_SEL_AN_MUTE_L 0x08
204 #define AUDIODAC_GPIO_OUT_SEL_AN_MUTE_R 0x09
205 #define AUDIODAC_GPIO_OUT_SEL_PLL_LOCK 0x0A
206 #define AUDIODAC_GPIO_OUT_SEL_UV_0_7_DVDD 0x0E
207 #define AUDIODAC_GPIO_OUT_SEL_UV_0_3_DVDD 0x0F
208 #define AUDIODAC_GPIO_OUT_SEL_PLL_OUT_DIV_4 0x10
209 
214 #define AUDIODAC_DIG_VOLUME_POS_MAX 0x00
215 #define AUDIODAC_DIG_VOLUME_NO_ATT 0x30
216 #define AUDIODAC_DIG_VOLUME_NEG_MIN 0xFE
217 #define AUDIODAC_DIG_VOLUME_MUTE 0xFF
218 
223 #define AUDIODAC_VOLUME_MAX 100
224 #define AUDIODAC_VOLUME_DEFAULT 48
225 #define AUDIODAC_VOLUME_MIN 1
226 #define AUDIODAC_VOLUME_MUTE 0
227 
232 #define AUDIODAC_CHANNEL_BOTH 0
233 #define AUDIODAC_CHANNEL_LEFT 1
234 #define AUDIODAC_CHANNEL_RIGHT 2
235 
241 #define AUDIODAC_DEVICE_ADDRESS 0x4C
242  // audiodac_set
244 
259 #define AUDIODAC_MAP_MIKROBUS( cfg, mikrobus ) \
260  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
261  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
262  cfg.mute = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
263  cfg.gpio4 = MIKROBUS( mikrobus, MIKROBUS_INT )
264  // audiodac_map // audiodac
267 
272 typedef struct
273 {
274  // Output pins
275  digital_out_t mute;
277  // Input pins
278  digital_in_t gpio4;
280  // Modules
281  i2c_master_t i2c;
283  // I2C slave address
284  uint8_t slave_address;
286 } audiodac_t;
287 
292 typedef struct
293 {
294  pin_name_t scl;
295  pin_name_t sda;
297  pin_name_t mute;
298  pin_name_t gpio4;
300  uint32_t i2c_speed;
301  uint8_t i2c_address;
304 
309 typedef enum
310 {
312  AUDIODAC_ERROR = -1
313 
315 
332 
347 
361 
376 err_t audiodac_generic_write ( audiodac_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
377 
392 err_t audiodac_generic_read ( audiodac_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
393 
406 err_t audiodac_write_register ( audiodac_t *ctx, uint8_t reg, uint8_t data_in );
407 
420 err_t audiodac_read_register ( audiodac_t *ctx, uint8_t reg, uint8_t *data_out );
421 
431 
441 
452 
464 err_t audiodac_select_page ( audiodac_t *ctx, uint8_t page_num );
465 
480 err_t audiodac_volume_control ( audiodac_t *ctx, uint8_t channel, uint8_t volume );
481 
482 #ifdef __cplusplus
483 }
484 #endif
485 #endif // AUDIODAC_H
486  // audiodac
488 
489 // ------------------------------------------------------------------------ END
AUDIODAC_ERROR
@ AUDIODAC_ERROR
Definition: audiodac.h:312
audiodac_t::gpio4
digital_in_t gpio4
Definition: audiodac.h:278
audiodac_cfg_t::mute
pin_name_t mute
Definition: audiodac.h:297
audiodac_default_cfg
err_t audiodac_default_cfg(audiodac_t *ctx)
Audio DAC default configuration function.
audiodac_volume_control
err_t audiodac_volume_control(audiodac_t *ctx, uint8_t channel, uint8_t volume)
Audio DAC volume control function.
AUDIODAC_OK
@ AUDIODAC_OK
Definition: audiodac.h:311
audiodac_mute_output
void audiodac_mute_output(audiodac_t *ctx)
Audio DAC mute output function.
audiodac_get_gpio4_pin
uint8_t audiodac_get_gpio4_pin(audiodac_t *ctx)
Audio DAC get gpio4 pin function.
audiodac_t::mute
digital_out_t mute
Definition: audiodac.h:275
audiodac_init
err_t audiodac_init(audiodac_t *ctx, audiodac_cfg_t *cfg)
Audio DAC initialization function.
audiodac_read_register
err_t audiodac_read_register(audiodac_t *ctx, uint8_t reg, uint8_t *data_out)
Audio DAC read register function.
audiodac_cfg_setup
void audiodac_cfg_setup(audiodac_cfg_t *cfg)
Audio DAC configuration object setup function.
audiodac_t::slave_address
uint8_t slave_address
Definition: audiodac.h:284
audiodac_cfg_t::gpio4
pin_name_t gpio4
Definition: audiodac.h:298
audiodac_cfg_t::i2c_address
uint8_t i2c_address
Definition: audiodac.h:301
audiodac_t::i2c
i2c_master_t i2c
Definition: audiodac.h:281
audiodac_return_value_t
audiodac_return_value_t
Audio DAC Click return value data.
Definition: audiodac.h:310
audiodac_generic_write
err_t audiodac_generic_write(audiodac_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Audio DAC I2C writing function.
audiodac_unmute_output
void audiodac_unmute_output(audiodac_t *ctx)
Audio DAC unmute output function.
audiodac_cfg_t::scl
pin_name_t scl
Definition: audiodac.h:294
audiodac_generic_read
err_t audiodac_generic_read(audiodac_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Audio DAC I2C reading function.
audiodac_select_page
err_t audiodac_select_page(audiodac_t *ctx, uint8_t page_num)
Audio DAC select page function.
audiodac_t
Audio DAC Click context object.
Definition: audiodac.h:273
audiodac_cfg_t
Audio DAC Click configuration object.
Definition: audiodac.h:293
audiodac_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: audiodac.h:300
audiodac_cfg_t::sda
pin_name_t sda
Definition: audiodac.h:295
audiodac_write_register
err_t audiodac_write_register(audiodac_t *ctx, uint8_t reg, uint8_t data_in)
Audio DAC write register function.