audioamp  2.0.0.0
audioamp.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 
34 #ifndef AUDIOAMP_H
35 #define AUDIOAMP_H
36 
41 #ifdef PREINIT_SUPPORTED
42 #include "preinit.h"
43 #endif
44 
45 #ifdef MikroCCoreVersion
46  #if MikroCCoreVersion >= 1
47  #include "delays.h"
48  #endif
49 #endif
50 
51 #include "drv_digital_in.h"
52 #include "drv_i2c_master.h"
53 
63 #define AUDIOAMP_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
65  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
66  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
67 
73 #define AUDIOAMP_OK 0
74 #define AUDIOAMP_INIT_ERROR (-1)
75 
81 #define AUDIOAMP_I2C_ADDRESS_0 0x7C
82 #define AUDIOAMP_I2C_ADDRESS_1 0x7D
83 
89 #define AUDIOAMP_IN_1 0x04
90 #define AUDIOAMP_IN_2 0x08
91 
97 #define AUDIOAMP_DG_EN 0x10
98 #define AUDIOAMP_DG_CONT 0x08
99 #define AUDIOAMP_DG_RESET 0x06
100 #define AUDIOAMP_DG_ILIMIT 0x04
101  // End group macro
104 
113 typedef struct
114 {
115  // Input pins
116 
117  digital_in_t int_pin;
118 
119  // Modules
120 
121  i2c_master_t i2c;
122 
123  // ctx variable
124 
125  uint8_t slave_address;
126 
127 } audioamp_t;
128 
132 typedef struct
133 {
134  // Communication gpio pins
135 
136  pin_name_t scl;
137  pin_name_t sda;
138 
139  // Additional gpio pins
140 
141  pin_name_t int_pin;
142 
143  // Static variable
144 
145  uint32_t i2c_speed;
146  uint8_t i2c_address;
147 
149  // End types group
151 
157 #ifdef __cplusplus
158 extern "C"{
159 #endif
160 
170 
182 
195 
207 
221 err_t audioamp_set_volume ( audioamp_t *ctx, uint8_t in_sel, uint8_t volume_level );
222 
234 err_t audioamp_mute ( audioamp_t *ctx );
235 
248 
261 
278 err_t audioamp_set_fault_detecton_control ( audioamp_t *ctx, uint8_t input_command );
279 
292 err_t audioamp_set_diagnostic_control ( audioamp_t *ctx, uint8_t input_command );
293 
305 
306 #ifdef __cplusplus
307 }
308 #endif
309 #endif // AUDIOAMP_H
310  // End public_function group // End Click Driver group
313 
314 // ------------------------------------------------------------------------ END
audioamp_set_fault_detecton_control
err_t audioamp_set_fault_detecton_control(audioamp_t *ctx, uint8_t input_command)
Set fault detection control function.
audioamp_init
err_t audioamp_init(audioamp_t *ctx, audioamp_cfg_t *cfg)
Initialization function.
audioamp_cfg_setup
void audioamp_cfg_setup(audioamp_cfg_t *cfg)
Config Object Initialization function.
audioamp_t
Click ctx object definition.
Definition: audioamp.h:114
audioamp_cfg_t::scl
pin_name_t scl
Definition: audioamp.h:136
audioamp_mute
err_t audioamp_mute(audioamp_t *ctx)
Mute input function.
audioamp_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: audioamp.h:145
audioamp_cfg_t::i2c_address
uint8_t i2c_address
Definition: audioamp.h:146
audioamp_cfg_t
Click configuration structure definition.
Definition: audioamp.h:133
audioamp_power_off
err_t audioamp_power_off(audioamp_t *ctx)
Turn off the Audio Amp Click function.
audioamp_cfg_t::int_pin
pin_name_t int_pin
Definition: audioamp.h:141
audioamp_set_volume
err_t audioamp_set_volume(audioamp_t *ctx, uint8_t in_sel, uint8_t volume_level)
Set volume function.
audioamp_check_fault
uint8_t audioamp_check_fault(audioamp_t *ctx)
Check Fault status function.
audioamp_set_diagnostic_control
err_t audioamp_set_diagnostic_control(audioamp_t *ctx, uint8_t input_command)
Set diagnostic control function.
audioamp_t::i2c
i2c_master_t i2c
Definition: audioamp.h:121
audioamp_cfg_t::sda
pin_name_t sda
Definition: audioamp.h:137
audioamp_unmute
err_t audioamp_unmute(audioamp_t *ctx)
Unmute input function.
audioamp_t::slave_address
uint8_t slave_address
Definition: audioamp.h:125
audioamp_t::int_pin
digital_in_t int_pin
Definition: audioamp.h:117
audioamp_set_fault_normal_operation
err_t audioamp_set_fault_normal_operation(audioamp_t *ctx)
Set normal opeation of Fault function.
audioamp_power_on
err_t audioamp_power_on(audioamp_t *ctx)
Turn on the Audio Amp Click function.