audioamp  2.0.0.0
audioamp.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef AUDIOAMP_H
36 #define AUDIOAMP_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define AUDIOAMP_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
57 
63 #define AUDIOAMP_RETVAL uint8_t
64 
65 #define AUDIOAMP_OK 0x00
66 #define AUDIOAMP_INIT_ERROR 0xFF
67 
73 #define AUDIOAMP_I2C_ADDRESS_0 0x7C
74 #define AUDIOAMP_I2C_ADDRESS_1 0x7D
75 
81 #define AUDIOAMP_REG_MODE 0x00
82 #define AUDIOAMP_REG_DIAG 0x20
83 #define AUDIOAMP_REG_FAULT 0x40
84 #define AUDIOAMP_REG_VOL_1 0x60
85 #define AUDIOAMP_REG_VOL_2 0x80
86 
92 #define AUDIOAMP_MODE_CH_1 0x00
93 #define AUDIOAMP_MODE_CH_2 0x01
94 #define AUDIOAMP_MODE_MUX 0x02
95 #define AUDIOAMP_MODE_MUTE 0x03
96 
102 #define AUDIOAMP_CMD_POWER_ON 0x1C
103 #define AUDIOAMP_CMD_POWER_OFF 0x00
104 #define AUDIOAMP_CMD_VOLUME_1 0x06
105 #define AUDIOAMP_CMD_VOLUME_2 0x08
106 #define AUDIOAMP_CMD_ENABLE 0x10
107 #define AUDIOAMP_CMD_DISABLE 0x00
108 
114 #define AUDIOAMP_CMD_DG_EN 0x10
115 #define AUDIOAMP_CMD_DG_CONT 0x08
116 #define AUDIOAMP_CMD_DG_RESET 0x06
117 #define AUDIOAMP_CMD_DG_ILIMIT 0x04
118 
124 #define AUDIOAMP_CH_1_BIT 0x04
125 #define AUDIOAMP_CH_2_BIT 0x08
126 #define AUDIOAMP_MUX_BIT 0x0C
127 #define AUDIOAMP_MUTE_BIT 0x00
128  // End group macro
131 
132 // --------------------------------------------------------------- PUBLIC TYPES
141 typedef struct
142 {
143  // Input pins
144 
145  digital_in_t int_pin;
146 
147  // Modules
148 
149  i2c_master_t i2c;
150 
151  // ctx variable
152 
153  hal_i2c_address_t slave_address;
154 
155 } audioamp_t;
156 
160 typedef struct
161 {
162  // Communication gpio pins
163 
164  pin_name_t scl;
165  pin_name_t sda;
166 
167  // Additional gpio pins
168 
169  pin_name_t int_pin;
170 
171  // static variable
172 
173  hal_i2c_speed_t i2c_speed;
174  hal_i2c_address_t i2c_address;
175 
177  // End types group
179 
180 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
181 
187 #ifdef __cplusplus
188 extern "C"{
189 #endif
190 
199 void audioamp_cfg_setup ( audioamp_cfg_t *cfg );
200 
209 
220 void audioamp_generic_write ( audioamp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
221 
233 void audioamp_generic_read ( audioamp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
234 
244 void audioamp_power_on ( audioamp_t *ctx );
245 
255 void audioamp_power_off ( audioamp_t *ctx );
256 
268 void audioamp_set_volume ( audioamp_t *ctx, uint8_t volume_value );
269 
285 void audioamp_set_volume_channel ( audioamp_t *ctx, uint8_t channel, uint8_t volume_value );
286 
296 void audioamp_enable ( audioamp_t *ctx );
297 
307 void audioamp_disable ( audioamp_t *ctx );
308 
318 void audioamp_mute_mode ( audioamp_t *ctx );
319 
329 void audioamp_unmute_mode ( audioamp_t *ctx );
330 
341 
357 void audioamp_set_fault_detecton_control( audioamp_t *ctx, uint8_t input_command );
358 
373 void audioamp_set_input( audioamp_t *ctx, uint8_t input_mode );
374 
388 uint8_t audioamp_check_status ( audioamp_t *ctx );
389 
390 #ifdef __cplusplus
391 }
392 #endif
393 #endif // _AUDIOAMP_H_
394  // End public_function group
397 
398 // ------------------------------------------------------------------------- END
audioamp_check_status
uint8_t audioamp_check_status(audioamp_t *ctx)
Check interrupt status function.
audioamp_disable
void audioamp_disable(audioamp_t *ctx)
Disable amplifier function.
audioamp_unmute_mode
void audioamp_unmute_mode(audioamp_t *ctx)
Set unmute mode function.
audioamp_cfg_setup
void audioamp_cfg_setup(audioamp_cfg_t *cfg)
Config Object Initialization function.
audioamp_generic_write
void audioamp_generic_write(audioamp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
audioamp_t
Click ctx object definition.
Definition: audioamp.h:141
audioamp_set_fault_detecton_control
void audioamp_set_fault_detecton_control(audioamp_t *ctx, uint8_t input_command)
Set fault detection control function.
audioamp_set_volume_channel
void audioamp_set_volume_channel(audioamp_t *ctx, uint8_t channel, uint8_t volume_value)
Set channel volume function.
audioamp_cfg_t::scl
pin_name_t scl
Definition: audioamp.h:164
audioamp_set_normal_operation
void audioamp_set_normal_operation(audioamp_t *ctx)
Set normal opeation function.
audioamp_cfg_t
Click configuration structure definition.
Definition: audioamp.h:160
audioamp_power_off
void audioamp_power_off(audioamp_t *ctx)
Turn off the Audio Amp click function.
audioamp_cfg_t::i2c_address
hal_i2c_address_t i2c_address
Definition: audioamp.h:174
audioamp_set_volume
void audioamp_set_volume(audioamp_t *ctx, uint8_t volume_value)
Set mux volume function.
audioamp_cfg_t::int_pin
pin_name_t int_pin
Definition: audioamp.h:169
audioamp_power_on
void audioamp_power_on(audioamp_t *ctx)
Turn on the Audio Amp click function.
audioamp_t::i2c
i2c_master_t i2c
Definition: audioamp.h:149
audioamp_cfg_t::sda
pin_name_t sda
Definition: audioamp.h:165
audioamp_mute_mode
void audioamp_mute_mode(audioamp_t *ctx)
Set mute mode function.
audioamp_generic_read
void audioamp_generic_read(audioamp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
audioamp_set_input
void audioamp_set_input(audioamp_t *ctx, uint8_t input_mode)
Set input mixer mode function.
audioamp_t::slave_address
hal_i2c_address_t slave_address
Definition: audioamp.h:153
audioamp_cfg_t::i2c_speed
hal_i2c_speed_t i2c_speed
Definition: audioamp.h:173
audioamp_enable
void audioamp_enable(audioamp_t *ctx)
Enable amplifier function.
audioamp_t::int_pin
digital_in_t int_pin
Definition: audioamp.h:145
audioamp_init
AUDIOAMP_RETVAL audioamp_init(audioamp_t *ctx, audioamp_cfg_t *cfg)
Initialization function.
AUDIOAMP_RETVAL
#define AUDIOAMP_RETVAL
Definition: audioamp.h:63