audioamp3  2.0.0.0
audioamp3.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 AUDIOAMP3_H
36 #define AUDIOAMP3_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define AUDIOAMP3_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.stb = MIKROBUS( mikrobus, MIKROBUS_RST ); \
66  cfg.clp = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
67  cfg.flt = MIKROBUS( mikrobus, MIKROBUS_INT )
68 
74 #define AUDIOAMP3_RETVAL uint8_t
75 #define AUDIOAMP3_STATUS_T uint8_t
76 
77 #define AUDIOAMP3_OK 0x00
78 #define AUDIOAMP3_INIT_ERROR 0xFF
79 
85 #define AUDIOAMP3_I2C_SLAVE_ADDRESS 0x6C
86 
92 #define AUDIOAMP3_DIAG_LATCHED_FAULT_REG_1 0x00
93 #define AUDIOAMP3_DIAG_LATCHED_FAULT_REG_2 0x01
94 #define AUDIOAMP3_DIAG_LATCHED_REG_1 0x02
95 #define AUDIOAMP3_DIAG_LATCHED_REG_2 0x03
96 
102 #define AUDIOAMP3_EXT_STATUS_REG_1 0x04
103 #define AUDIOAMP3_EXT_STATUS_REG_2 0x05
104 #define AUDIOAMP3_EXT_STATUS_REG_3 0x06
105 #define AUDIOAMP3_EXT_STATUS_REG_4 0x07
106 #define AUDIOAMP3_EXT_STATUS_REG_5 0x11
107 
113 #define AUDIOAMP3_EXT_CTRL_REG_1 0x08
114 #define AUDIOAMP3_EXT_CTRL_REG_2 0x09
115 #define AUDIOAMP3_EXT_CTRL_REG_3 0x0A
116 #define AUDIOAMP3_EXT_CTRL_REG_4 0x0B
117 #define AUDIOAMP3_EXT_CTRL_REG_5 0x0C
118 #define AUDIOAMP3_EXT_CTRL_REG_6 0x0D
119 #define AUDIOAMP3_EXT_CTRL_REG_7 0x10
120 
126 #define AUDIOAMP3_SEL_CH_1_GAIN_12dB 0x00
127 #define AUDIOAMP3_SEL_CH_1_GAIN_20dB 0x01
128 #define AUDIOAMP3_SEL_CH_1_GAIN_32dB 0x03
129 #define AUDIOAMP3_SEL_CH_2_GAIN_12dB 0x00
130 #define AUDIOAMP3_SEL_CH_2_GAIN_20dB 0x04
131 #define AUDIOAMP3_SEL_CH_2_GAIN_32dB 0x0C
132 #define AUDIOAMP3_SEL_CH_3_GAIN_12dB 0x00
133 #define AUDIOAMP3_SEL_CH_3_GAIN_20dB 0x10
134 #define AUDIOAMP3_SEL_CH_3_GAIN_32dB 0x30
135 #define AUDIOAMP3_SEL_CH_4_GAIN_12dB 0x00
136 #define AUDIOAMP3_SEL_CH_4_GAIN_20dB 0x40
137 #define AUDIOAMP3_SEL_CH_4_GAIN_32dB 0xC0
138 #define AUDIOAMP3_SEL_ALL_CH_GAIN_26dB 0xAA
139 
145 #define AUDIOAMP3_OVERCURR_CH_1_LIMIT_LVL_1 0x00
146 #define AUDIOAMP3_OVERCURR_CH_1_LIMIT_LVL_2 0x10
147 #define AUDIOAMP3_OVERCURR_CH_2_LIMIT_LVL_1 0x00
148 #define AUDIOAMP3_OVERCURR_CH_2_LIMIT_LVL_2 0x20
149 #define AUDIOAMP3_OVERCURR_CH_3_LIMIT_LVL_1 0x00
150 #define AUDIOAMP3_OVERCURR_CH_3_LIMIT_LVL_2 0x40
151 #define AUDIOAMP3_OVERCURR_CH_4_LIMIT_LVL_1 0x00
152 #define AUDIOAMP3_OVERCURR_CH_4_LIMIT_LVL_2 0x80
153 #define AUDIOAMP3_CURRENT_LIMIT_LVL_2_ALL_CH 0xF0
154 #define AUDIOAMP3_DIS_THERMAL_FOLDBACK 0x01
155 
161 #define AUDIOAMP3_FREQ_SEL_417_kHZ_45_PHASE_CLIP_OTWT 0x0D
162 #define AUDIOAMP3_FREQ_SEL_500_kHZ 0x00
163 #define AUDIOAMP3_FREQ_SEL_357_kHZ 0x02
164 #define AUDIOAMP3_CONFIG_CLIP_OTW_TWEETER_DETECT 0x00
165 #define AUDIOAMP3_CONFIG_CLIP_OTW_CLIP_DETECT 0x04
166 #define AUDIOAMP3_CONFIG_CLIP_OTW_OVERTEMP_WARNING 0x08
167 #define AUDIOAMP3_ENABLE_HARD_STOP_MODE 0x10
168 #define AUDIOAMP3_SET_FS_357_kHZ_180_PHASE_CLIP_OTWT 0x20
169 #define AUDIOAMP3_SEND_SYNC_PULSE_OSC_SYNC 0x40
170 #define AUDIOAMP3_CONFIG_CLIP_OTW_THERMAL_FOLDBACK 0x80
171 
177 #define AUDIOAMP3_LOAD_DIAG_RUN_CH_1 0x01
178 #define AUDIOAMP3_LOAD_DIAG_RUN_CH_2 0x02
179 #define AUDIOAMP3_LOAD_DIAG_RUN_CH_3 0x04
180 #define AUDIOAMP3_LOAD_DIAG_RUN_CH_4 0x08
181 #define AUDIOAMP3_SET_CLOCK_OUTPUT_DISABLED 0x50
182 #define AUDIOAMP3_DIS_DC_DETECTION_ALL_CH 0x00
183 #define AUDIOAMP3_EN_TWEETER_DETECT_MODE 0x20
184 #define AUDIOAMP3_EN_CLOCK_OUTPUT_OSC_SYNC 0x80
185 
191 #define AUDIOAMP3_OUT_CTRL_ALL_CH_HI_Z_MUTE_RST_DIS_DC_EN 0x1F
192 #define AUDIOAMP3_OUT_CTRL_SET_CH_1_2_3_4_MUTE 0x00
193 #define AUDIOAMP3_OUT_CTRL_SET_PLAY_MODE 0x20
194 #define AUDIOAMP3_OUT_CTRL_DC_DET_SHUTDOWN_DIS 0x40
195 #define AUDIOAMP3_OUT_CTRL_RST_DEVICE 0x80
196 #define AUDIOAMP3_OUT_CTRL_L_LOW_STATE_DIS_ALL_CH 0x00
197 #define AUDIOAMP3_OUT_CTRL_SET_CH_1_L_LOW_STATE 0xC1
198 #define AUDIOAMP3_OUT_CTRL_SET_CH_2_L_LOW_STATE 0xC2
199 #define AUDIOAMP3_OUT_CTRL_SET_CH_3_L_LOW_STATE 0xC4
200 #define AUDIOAMP3_OUT_CTRL_SET_CH_4_L_LOW_STATE 0xC8
201 #define AUDIOAMP3_OUT_CTRL_CONN_CH_1_2_BTL_MODE 0xD0
202 #define AUDIOAMP3_OUT_CTRL_CONN_CH_3_4_BTL_MODE 0xE0
203 
209 #define AUDIOAMP3_MISCELL_NORMAL_SPEED_S2P_S2G_TIMING 0x01
210 #define AUDIOAMP3_MISCELL_MIN_DC_DET_VAL_0_8_V 0x00
211 #define AUDIOAMP3_MISCELL_MIN_DC_DET_VAL_2_4_V 0x02
212 #define AUDIOAMP3_MISCELL_EN_CROSSTALK_ENHANCEMENT 0x04
213 #define AUDIOAMP3_MISCELL_N_LOAD_DIAG_PHASES 0x08
214 #define AUDIOAMP3_MISCELL_S2P_S2G_LOAD_DIAG 0x10
215 #define AUDIOAMP3_MISCELL_SLOW_COMMON_MODE_RAMP 0x20
216 #define AUDIOAMP3_MISCELL_SLOWER_CM_RAMP_DOWN_MUTE_MODE 0x80
217 
223 #define AUDIOAMP3_MASK_BIT_SEL_NO_CH 0x00
224 #define AUDIOAMP3_MASK_BIT_SEL_CH_1 0x01
225 #define AUDIOAMP3_MASK_BIT_SEL_CH_2 0x02
226 #define AUDIOAMP3_MASK_BIT_SEL_ALL_CH 0x03
227 #define AUDIOAMP3_MASK_BIT_SEL_GAIN_12dB 0x0C
228 #define AUDIOAMP3_MASK_BIT_SEL_GAIN_20dB 0x14
229 #define AUDIOAMP3_MASK_BIT_SEL_GAIN_26dB 0x1A
230 #define AUDIOAMP3_MASK_BIT_SEL_GAIN_32dB 0x20
231 #define AUDIOAMP3_MASK_BIT_CH_1 0xFC
232 #define AUDIOAMP3_MASK_BIT_MUTE_NO_CH 0x10
233 #define AUDIOAMP3_MASK_BIT_MUTE_CH_1 0xFE
234 #define AUDIOAMP3_MASK_BIT_MUTE_CH_2 0xFD
235 
241 #define AUDIOAMP3_GAIN_VAL_MAX 0x04
242 #define AUDIOAMP3_GAIN_VAL_MEDIUM 0x03
243 #define AUDIOAMP3_GAIN_VAL_MIN 0x01
244 #define AUDIOAMP3_GAIN_VAL_0 0x00
245 #define AUDIOAMP3_GAIN_VAL_5 0x05
246 #define AUDIOAMP3_GAIN_VAL_LVL_1_12dB 0x01
247 #define AUDIOAMP3_GAIN_VAL_LVL_2_20dB 0x02
248 #define AUDIOAMP3_GAIN_VAL_LVL_3_26dB 0x03
249 #define AUDIOAMP3_GAIN_VAL_LVL_4_32dB 0x04
250 
256 #define AUDIOAMP3_STATUS_ERR 0x00
257 #define AUDIOAMP3_STATUS_OK 0x01
258  // End group macro
261 
262 // --------------------------------------------------------------- PUBLIC TYPES
271 typedef struct
272 {
273  // Output pins
274 
275  digital_out_t stb;
276 
277  // Input pins
278 
279  digital_in_t clp;
280  digital_in_t flt;
281 
282  // Modules
283 
284  i2c_master_t i2c;
285 
286  // ctx variable
287 
288  uint8_t slave_address;
289 
290 } audioamp3_t;
291 
295 typedef struct
296 {
297  // Communication gpio pins
298 
299  pin_name_t scl;
300  pin_name_t sda;
301 
302  // Additional gpio pins
303 
304  pin_name_t stb;
305  pin_name_t clp;
306  pin_name_t flt;
307 
308  // static variable
309 
310  uint32_t i2c_speed;
311  uint8_t i2c_address;
312 
314  // End types group
316 
317 // ------------------------------------------------------------------ CONSTANTS // End constants group
325 
326 // ------------------------------------------------------------------ VARIABLES // End variable group
334 
335 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
336 
342 #ifdef __cplusplus
343 extern "C"{
344 #endif
345 
355 
365 
376 void audioamp3_generic_write ( audioamp3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
377 
389 void audioamp3_generic_read ( audioamp3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
390 
400 
412 
423 void audioamp3_read_all_diagnostics ( audioamp3_t *ctx, uint8_t *p_all_diagnostics );
424 
451 
480 
501 
521 
551 
552 #ifdef __cplusplus
553 }
554 #endif
555 #endif // _AUDIOAMP3_H_
556  // End public_function group
559 
560 // ------------------------------------------------------------------------- END
audioamp3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: audioamp3.h:310
audioamp3_generic_write
void audioamp3_generic_write(audioamp3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
audioamp3_cfg_setup
void audioamp3_cfg_setup(audioamp3_cfg_t *cfg)
Config Object Initialization function.
audioamp3_t::slave_address
uint8_t slave_address
Definition: audioamp3.h:288
audioamp3_set_gain_lvl
AUDIOAMP3_STATUS_T audioamp3_set_gain_lvl(audioamp3_t *ctx, uint8_t gain_lvl)
Set the gain lvl function.
audioamp3_set_channel_low_to_low
AUDIOAMP3_STATUS_T audioamp3_set_channel_low_to_low(audioamp3_t *ctx, uint8_t s_channel)
Set the channel to low-low state function.
AUDIOAMP3_STATUS_T
#define AUDIOAMP3_STATUS_T
Definition: audioamp3.h:75
audioamp3_cfg_t::scl
pin_name_t scl
Definition: audioamp3.h:299
audioamp3_cfg_t
Click configuration structure definition.
Definition: audioamp3.h:296
AUDIOAMP3_RETVAL
#define AUDIOAMP3_RETVAL
Definition: audioamp3.h:74
audioamp3_run_channel_diagnostics
AUDIOAMP3_STATUS_T audioamp3_run_channel_diagnostics(audioamp3_t *ctx, uint8_t rc_channel)
Run channel diagnostics function.
audioamp3_cfg_t::sda
pin_name_t sda
Definition: audioamp3.h:300
audioamp3_hw_reset
void audioamp3_hw_reset(audioamp3_t *ctx)
Hardware reset function.
audioamp3_cfg_t::i2c_address
uint8_t i2c_address
Definition: audioamp3.h:311
audioamp3_t::i2c
i2c_master_t i2c
Definition: audioamp3.h:284
audioamp3_t::clp
digital_in_t clp
Definition: audioamp3.h:279
audioamp3_cfg_t::flt
pin_name_t flt
Definition: audioamp3.h:306
audioamp3_t::stb
digital_out_t stb
Definition: audioamp3.h:275
audioamp3_init
AUDIOAMP3_RETVAL audioamp3_init(audioamp3_t *ctx, audioamp3_cfg_t *cfg)
Initialization function.
audioamp3_generic_read
void audioamp3_generic_read(audioamp3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
audioamp3_power_up
void audioamp3_power_up(audioamp3_t *ctx)
Power Up function.
audioamp3_t::flt
digital_in_t flt
Definition: audioamp3.h:280
audioamp3_set_channel_mute_mode
AUDIOAMP3_STATUS_T audioamp3_set_channel_mute_mode(audioamp3_t *ctx, uint8_t s_channel)
Set the mute mode of channel function.
audioamp3_cfg_t::clp
pin_name_t clp
Definition: audioamp3.h:305
audioamp3_t
Click ctx object definition.
Definition: audioamp3.h:272
audioamp3_cfg_t::stb
pin_name_t stb
Definition: audioamp3.h:304
audioamp3_read_all_diagnostics
void audioamp3_read_all_diagnostics(audioamp3_t *ctx, uint8_t *p_all_diagnostics)
Read all diagnostics function.
audioamp3_set_play_mode
AUDIOAMP3_STATUS_T audioamp3_set_play_mode(audioamp3_t *ctx)
Set the play mode for all channels function.