audioamp11  2.1.0.0
audioamp11.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 AUDIOAMP11_H
29 #define AUDIOAMP11_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 
49 
50 
51 
72 #define AUDIOAMP11_REG_REGGAIN 0x04
73 #define AUDIOAMP11_REG_VOLCTRL 0x1B
74  // audioamp11_reg
76 
91 #define AUDIOAMP11_GS_0dB_VOLCTRL_0dB 0x00
92 #define AUDIOAMP11_GS_0dB_VOLCTRL_m2dB 0x01
93 #define AUDIOAMP11_GS_0dB_VOLCTRL_m4dB 0x02
94 #define AUDIOAMP11_GS_0dB_VOLCTRL_m6dB 0x03
95 #define AUDIOAMP11_GS_0dB_VOLCTRL_m8dB 0x04
96 #define AUDIOAMP11_GS_0dB_VOLCTRL_m10dB 0x05
97 #define AUDIOAMP11_GS_0dB_VOLCTRL_m12dB 0x06
98 #define AUDIOAMP11_GS_0dB_VOLCTRL_m14dB 0x07
99 #define AUDIOAMP11_GS_0dB_VOLCTRL_m16dB 0x08
100 #define AUDIOAMP11_GS_0dB_VOLCTRL_m18dB 0x09
101 #define AUDIOAMP11_GS_0dB_VOLCTRL_m20dB 0x0A
102 #define AUDIOAMP11_GS_0dB_VOLCTRL_m22dB 0x0B
103 #define AUDIOAMP11_GS_0dB_VOLCTRL_m24dB 0x0C
104 #define AUDIOAMP11_GS_0dB_VOLCTRL_m26dB 0x0D
105 #define AUDIOAMP11_GS_0dB_VOLCTRL_m28dB 0x0E
106 #define AUDIOAMP11_GS_0dB_VOLCTRL_m30dB 0x0F
107 #define AUDIOAMP11_GS_0dB_VOLCTRL_m32dB 0x10
108 #define AUDIOAMP11_GS_0dB_VOLCTRL_m34dB 0x11
109 #define AUDIOAMP11_GS_0dB_VOLCTRL_m36dB 0x12
110 #define AUDIOAMP11_GS_0dB_VOLCTRL_m38dB 0x13
111 #define AUDIOAMP11_GS_0dB_VOLCTRL_m40dB 0x14
112 #define AUDIOAMP11_GS_0dB_VOLCTRL_m42dB 0x15
113 #define AUDIOAMP11_GS_0dB_VOLCTRL_m44dB 0x16
114 #define AUDIOAMP11_GS_0dB_VOLCTRL_m46dB 0x17
115 #define AUDIOAMP11_GS_0dB_VOLCTRL_m48dB 0x18
116 #define AUDIOAMP11_GS_0dB_VOLCTRL_m50dB 0x19
117 #define AUDIOAMP11_GS_0dB_VOLCTRL_m52dB 0x1A
118 #define AUDIOAMP11_GS_0dB_VOLCTRL_m54dB 0x1B
119 #define AUDIOAMP11_GS_0dB_VOLCTRL_m56dB 0x1C
120 #define AUDIOAMP11_GS_0dB_VOLCTRL_m58dB 0x1D
121 #define AUDIOAMP11_GS_0dB_VOLCTRL_m60dB 0x1E
122 #define AUDIOAMP11_GS_0dB_VOLCTRL_m62dB 0x1F
123 #define AUDIOAMP11_GS_6dB_VOLCTRL_6dB 0x00
124 #define AUDIOAMP11_GS_6dB_VOLCTRL_4_1dB 0x01
125 #define AUDIOAMP11_GS_6dB_VOLCTRL_2_2dB 0x02
126 #define AUDIOAMP11_GS_6dB_VOLCTRL_0_4dB 0x03
127 #define AUDIOAMP11_GS_6dB_VOLCTRL_m1_6dB 0x04
128 #define AUDIOAMP11_GS_6dB_VOLCTRL_m3_5dB 0x05
129 #define AUDIOAMP11_GS_6dB_VOLCTRL_m5_6dB 0x06
130 #define AUDIOAMP11_GS_6dB_VOLCTRL_m7_5dB 0x07
131 #define AUDIOAMP11_GS_6dB_VOLCTRL_m9_5dB 0x08
132 #define AUDIOAMP11_GS_6dB_VOLCTRL_m11_4dB 0x09
133 #define AUDIOAMP11_GS_6dB_VOLCTRL_m13_4dB 0x0A
134 #define AUDIOAMP11_GS_6dB_VOLCTRL_m15_4dB 0x0B
135 #define AUDIOAMP11_GS_6dB_VOLCTRL_m17_3dB 0x0C
136 #define AUDIOAMP11_GS_6dB_VOLCTRL_m19_3dB 0x0D
137 #define AUDIOAMP11_GS_6dB_VOLCTRL_m21_3dB 0x0E
138 #define AUDIOAMP11_GS_6dB_VOLCTRL_m23_3dB 0x0F
139 #define AUDIOAMP11_GS_6dB_VOLCTRL_m25_3dB 0x10
140 #define AUDIOAMP11_GS_6dB_VOLCTRL_m27_3dB 0x11
141 #define AUDIOAMP11_GS_6dB_VOLCTRL_m29_1dB 0x12
142 #define AUDIOAMP11_GS_6dB_VOLCTRL_m30_7dB 0x13
143 #define AUDIOAMP11_GS_6dB_VOLCTRL_m32_2dB 0x14
144 #define AUDIOAMP11_GS_6dB_VOLCTRL_m33_7dB 0x15
145 #define AUDIOAMP11_GS_6dB_VOLCTRL_m35_1dB 0x16
146 #define AUDIOAMP11_GS_6dB_VOLCTRL_m36_6dB 0x17
147 #define AUDIOAMP11_GS_6dB_VOLCTRL_m36dB 0x18
148 #define AUDIOAMP11_GS_6dB_VOLCTRL_m35_2dB 0x19
149 #define AUDIOAMP11_GS_6dB_VOLCTRL_m34_6dB 0x1A
150 #define AUDIOAMP11_GS_6dB_VOLCTRL_m33_9dB 0x1B
151 #define AUDIOAMP11_GS_6dB_VOLCTRL_m33_5dB 0x1D
152 #define AUDIOAMP11_GS_6dB_VOLCTRL_m33_4dB 0x1E
153 #define AUDIOAMP11_GS_6dB_VOLCTRL_m62dB 0x1F
154 #define AUDIOAMP11_GS_12dB_VOLCTRL_12dB 0x00
155 #define AUDIOAMP11_GS_12dB_VOLCTRL_10_4dB 0x01
156 #define AUDIOAMP11_GS_12dB_VOLCTRL_8_8dB 0x02
157 #define AUDIOAMP11_GS_12dB_VOLCTRL_7_1dB 0x03
158 #define AUDIOAMP11_GS_12dB_VOLCTRL_5_4dB 0x04
159 #define AUDIOAMP11_GS_12dB_VOLCTRL_3_6dB 0x05
160 #define AUDIOAMP11_GS_12dB_VOLCTRL_1_7dB 0x06
161 #define AUDIOAMP11_GS_12dB_VOLCTRL_m0_2dB 0x07
162 #define AUDIOAMP11_GS_12dB_VOLCTRL_m2dB 0x08
163 #define AUDIOAMP11_GS_12dB_VOLCTRL_m3_9dB 0x09
164 #define AUDIOAMP11_GS_12dB_VOLCTRL_m5_8dB 0x0A
165 #define AUDIOAMP11_GS_12dB_VOLCTRL_m7_8dB 0x0B
166 #define AUDIOAMP11_GS_12dB_VOLCTRL_m9_7dB 0x0C
167 #define AUDIOAMP11_GS_12dB_VOLCTRL_m11_7dB 0x0D
168 #define AUDIOAMP11_GS_12dB_VOLCTRL_m13_6dB 0x0E
169 #define AUDIOAMP11_GS_12dB_VOLCTRL_m15_6dB 0x0F
170 #define AUDIOAMP11_GS_12dB_VOLCTRL_m17_6dB 0x10
171 #define AUDIOAMP11_GS_12dB_VOLCTRL_m19_3dB 0x11
172 #define AUDIOAMP11_GS_12dB_VOLCTRL_m20_4dB 0x12
173 #define AUDIOAMP11_GS_12dB_VOLCTRL_m20_5dB 0x13
174 #define AUDIOAMP11_GS_12dB_VOLCTRL_m20_2dB 0x14
175 #define AUDIOAMP11_GS_12dB_VOLCTRL_m20dB 0x15
176 #define AUDIOAMP11_GS_12dB_VOLCTRL_m19_8dB 0x16
177 #define AUDIOAMP11_GS_12dB_VOLCTRL_m19_7dB 0x17
178 #define AUDIOAMP11_GS_12dB_VOLCTRL_m19_6dB 0x18
179 #define AUDIOAMP11_GS_12dB_VOLCTRL_m19_5dB 0x19
180 #define AUDIOAMP11_GS_12dB_VOLCTRL_m19_4dB 0x1B
181 #define AUDIOAMP11_GS_18dB_VOLCTRL_18dB 0x00
182 #define AUDIOAMP11_GS_18dB_VOLCTRL_17dB 0x01
183 #define AUDIOAMP11_GS_18dB_VOLCTRL_16dB 0x02
184 #define AUDIOAMP11_GS_18dB_VOLCTRL_15dB 0x03
185 #define AUDIOAMP11_GS_18dB_VOLCTRL_13_7dB 0x04
186 #define AUDIOAMP11_GS_18dB_VOLCTRL_12_4dB 0x05
187 #define AUDIOAMP11_GS_18dB_VOLCTRL_10_9dB 0x06
188 #define AUDIOAMP11_GS_18dB_VOLCTRL_9_4dB 0x07
189 #define AUDIOAMP11_GS_18dB_VOLCTRL_7_9dB 0x08
190 #define AUDIOAMP11_GS_18dB_VOLCTRL_6_2dB 0x09
191 #define AUDIOAMP11_GS_18dB_VOLCTRL_4_5dB 0x0A
192 #define AUDIOAMP11_GS_18dB_VOLCTRL_2_7dB 0x0B
193 #define AUDIOAMP11_GS_18dB_VOLCTRL_0_9dB 0x0C
194 #define AUDIOAMP11_GS_18dB_VOLCTRL_m0_9dB 0x0D
195 #define AUDIOAMP11_GS_18dB_VOLCTRL_m2_8dB 0x0E
196 #define AUDIOAMP11_GS_18dB_VOLCTRL_m4_7dB 0x0F
197 #define AUDIOAMP11_GS_18dB_VOLCTRL_m6_6dB 0x10
198 #define AUDIOAMP11_GS_18dB_VOLCTRL_m7_3dB 0x11
199 #define AUDIOAMP11_GS_18dB_VOLCTRL_m7_1dB 0x14
200 #define AUDIOAMP11_GS_18dB_VOLCTRL_m7_0dB 0x18
201 #define AUDIOAMP11_GS_24dB_VOLCTRL_24dB 0x00
202 
203 #define AUDIOAMP11_VOLUME_LEVEL_31 0x00
204 #define AUDIOAMP11_VOLUME_LEVEL_30 0x01
205 #define AUDIOAMP11_VOLUME_LEVEL_29 0x02
206 #define AUDIOAMP11_VOLUME_LEVEL_28 0x03
207 #define AUDIOAMP11_VOLUME_LEVEL_27 0x04
208 #define AUDIOAMP11_VOLUME_LEVEL_26 0x05
209 #define AUDIOAMP11_VOLUME_LEVEL_25 0x06
210 #define AUDIOAMP11_VOLUME_LEVEL_24 0x07
211 #define AUDIOAMP11_VOLUME_LEVEL_23 0x08
212 #define AUDIOAMP11_VOLUME_LEVEL_22 0x09
213 #define AUDIOAMP11_VOLUME_LEVEL_21 0x0A
214 #define AUDIOAMP11_VOLUME_LEVEL_20 0x0B
215 #define AUDIOAMP11_VOLUME_LEVEL_19 0x0C
216 #define AUDIOAMP11_VOLUME_LEVEL_18 0x0D
217 #define AUDIOAMP11_VOLUME_LEVEL_17 0x0E
218 #define AUDIOAMP11_VOLUME_LEVEL_16 0x0F
219 #define AUDIOAMP11_VOLUME_LEVEL_15 0x10
220 #define AUDIOAMP11_VOLUME_LEVEL_14 0x11
221 #define AUDIOAMP11_VOLUME_LEVEL_13 0x12
222 #define AUDIOAMP11_VOLUME_LEVEL_12 0x13
223 #define AUDIOAMP11_VOLUME_LEVEL_11 0x14
224 #define AUDIOAMP11_VOLUME_LEVEL_10 0x15
225 #define AUDIOAMP11_VOLUME_LEVEL_9 0x16
226 #define AUDIOAMP11_VOLUME_LEVEL_8 0x17
227 #define AUDIOAMP11_VOLUME_LEVEL_7 0x18
228 #define AUDIOAMP11_VOLUME_LEVEL_6 0x19
229 #define AUDIOAMP11_VOLUME_LEVEL_5 0x1A
230 #define AUDIOAMP11_VOLUME_LEVEL_4 0x1B
231 #define AUDIOAMP11_VOLUME_LEVEL_3 0x1C
232 #define AUDIOAMP11_VOLUME_LEVEL_2 0x1D
233 #define AUDIOAMP11_VOLUME_LEVEL_1 0x1E
234 #define AUDIOAMP11_VOLUME_LEVEL_0 0x1F
235 #define AUDIOAMP11_VOLUME_MUTE 0x3F
236 
237 #define AUDIOAMP11_GAINDEC_0dB 0x01
238 #define AUDIOAMP11_GAINDEC_6dB 0x02
239 #define AUDIOAMP11_GAINDEC_12dB 0x04
240 #define AUDIOAMP11_GAINDEC_18dB 0x08
241 #define AUDIOAMP11_GAINDEC_24dB 0x10
242 
248 #define AUDIOAMP11_DEVICE_ADDRESS 0x2A
249  // audioamp11_set
251 
261 #define AUDIOAMP11_CALC_GAIN_CONFIG(GAINDEC) (GAINDEC==1?0:(GAINDEC==2?6:(GAINDEC==4?12:(GAINDEC==8 ? 18:24))))
262 
263 #define OUTPUT_VOLUME_0dB 0.0, -2.0, -4.0, -6.0, -8.0, -10.0, -12.0, -14.0, -16.0, -18.0, \
264  -20.0, -22.0, -24.0, -26.0, -28.0, -30.0, -32.0, -34.0, -36.0, -38.0, \
265  -40.0, -42.0, -44.0, -46.0, -48.0, -50.0, -52.0, -54.0, -56.0, -58.0, -60.0, -62.0
266 
267 #define OUTPUT_VOLUME_6dB 6.0, 4.1, 2.2, 0.4, -1.6, -3.5, -5.6, -7.5, -29.5, -11.4 , \
268  -13.4, -15.4, -17.3, -19.3, -21.3, -23.3, -25.3, -27.3, -29.1, -30.7, \
269  -32.2, -33.7, -35.1, -36.6, -36.0, -35.2, -34.6, -34.2, -33.9, -33.7, -33.5, -33.4
270 
271 #define OUTPUT_VOLUME_12dB 12.0, 10.4, 8.8, 7.1, 5.4, 3.6, 1.7, -0.2, -2.0, -3.9, \
272  -5.8, -7.8, -9.7, -11.7, -13.6, -15.6, -17.6, -19.3, -20.4, -20.5, \
273  -20.2, -20.0, -19.8, -19.7, -19.6, -19.5, -19.5, -19.4, -19.4, -19.4, -19.4, -19.3
274 
275 #define OUTPUT_VOLUME_18dB 19.0, 17.0, 16.0, 15.0, 13.7, 12.4, 10.9, 9.4, 7.9, 6.2, \
276  4.5, 2.7, 0.9, -0.9, -2.8, -4.7, -6.6, -7.3, -7.3, -7.1, \
277  -7.1, -7.1, -7.1, -7.0, -7.0, -7.0, -7.0, -7.0, -7.0, -7.0, -7.0, -7.0
278 
279 #define OUTPUT_VOLUME_24dB 24.0
280  // audioamp11_volume_control
282 
297 #define AUDIOAMP11_MAP_MIKROBUS( cfg, mikrobus ) \
298  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
299  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
300  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST )
301  // audioamp11_map // audioamp11
304 
309 typedef struct
310 {
311  // Output pins
312  digital_out_t en;
314  // Modules
315  i2c_master_t i2c;
317  // I2C slave address
318  uint8_t slave_address;
320 } audioamp11_t;
321 
326 typedef struct
327 {
328  pin_name_t scl;
329  pin_name_t sda;
331  pin_name_t en;
333  uint32_t i2c_speed;
334  uint8_t i2c_address;
337 
342 typedef enum
343 {
345  AUDIOAMP11_ERROR = -1
346 
348 
349 
366 
381 
395 
409 err_t audioamp11_generic_write ( audioamp11_t *ctx, uint8_t reg, uint8_t data_in );
410 
424 err_t audioamp11_generic_read ( audioamp11_t *ctx, uint8_t reg, uint8_t *data_out );
425 
438 
451 
465 err_t audioamp11_check_gain ( audioamp11_t *ctx, uint8_t *gain );
466 
480 err_t audioamp11_get_output_volume_level ( audioamp11_t *ctx, uint8_t *volume_data );
481 
495 err_t audioamp11_set_output_volume_level ( audioamp11_t *ctx, uint8_t volume_data );
496 
497 #ifdef __cplusplus
498 }
499 #endif
500 #endif // AUDIOAMP11_H
501  // audioamp11
503 
504 // ------------------------------------------------------------------------ END
audioamp11_get_output_volume_level
err_t audioamp11_get_output_volume_level(audioamp11_t *ctx, uint8_t *volume_data)
AudioAMP 11 get output volume level function.
audioamp11_cfg_t::scl
pin_name_t scl
Definition: audioamp11.h:328
audioamp11_return_value_t
audioamp11_return_value_t
AudioAMP 11 Click return value data.
Definition: audioamp11.h:343
audioamp11_disable_device
void audioamp11_disable_device(audioamp11_t *ctx)
AudioAMP 11 enable device function.
audioamp11_cfg_t::en
pin_name_t en
Definition: audioamp11.h:331
audioamp11_generic_write
err_t audioamp11_generic_write(audioamp11_t *ctx, uint8_t reg, uint8_t data_in)
AudioAMP 11 I2C writing function.
AUDIOAMP11_OK
@ AUDIOAMP11_OK
Definition: audioamp11.h:344
audioamp11_t::slave_address
uint8_t slave_address
Definition: audioamp11.h:318
audioamp11_cfg_t::i2c_address
uint8_t i2c_address
Definition: audioamp11.h:334
audioamp11_set_output_volume_level
err_t audioamp11_set_output_volume_level(audioamp11_t *ctx, uint8_t volume_data)
AudioAMP 11 set output volume level function.
audioamp11_t::en
digital_out_t en
Definition: audioamp11.h:312
audioamp11_t
AudioAMP 11 Click context object.
Definition: audioamp11.h:310
AUDIOAMP11_ERROR
@ AUDIOAMP11_ERROR
Definition: audioamp11.h:345
audioamp11_init
err_t audioamp11_init(audioamp11_t *ctx, audioamp11_cfg_t *cfg)
AudioAMP 11 initialization function.
audioamp11_cfg_setup
void audioamp11_cfg_setup(audioamp11_cfg_t *cfg)
AudioAMP 11 configuration object setup function.
audioamp11_generic_read
err_t audioamp11_generic_read(audioamp11_t *ctx, uint8_t reg, uint8_t *data_out)
AudioAMP 11 I2C reading function.
audioamp11_cfg_t
AudioAMP 11 Click configuration object.
Definition: audioamp11.h:327
audioamp11_t::i2c
i2c_master_t i2c
Definition: audioamp11.h:315
audioamp11_check_gain
err_t audioamp11_check_gain(audioamp11_t *ctx, uint8_t *gain)
AudioAMP 11 check gain function.
audioamp11_cfg_t::sda
pin_name_t sda
Definition: audioamp11.h:329
audioamp11_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: audioamp11.h:333
audioamp11_default_cfg
err_t audioamp11_default_cfg(audioamp11_t *ctx)
AudioAMP 11 default configuration function.
audioamp11_enable_device
void audioamp11_enable_device(audioamp11_t *ctx)
AudioAMP 11 enable device function.