stereoamp  2.0.0.0
stereoamp.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  */
32 // ----------------------------------------------------------------------------
33 
34 #ifndef STEREOAMP_H
35 #define STEREOAMP_H
36 
37 #include "mikrosdk_version.h"
38 
39 #ifdef __GNUC__
40 #if mikroSDK_GET_VERSION < 20800ul
41 #include "rcu_delays.h"
42 #else
43 #include "delays.h"
44 #endif
45 #endif
46 
47 #include "drv_digital_in.h"
48 #include "drv_i2c_master.h"
49 
50 // -------------------------------------------------------------- PUBLIC MACROS
60 #define STEREOAMP_MAP_MIKROBUS( cfg, mikrobus ) \
61  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
62  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
63  cfg.fll = MIKROBUS( mikrobus, MIKROBUS_AN ); \
64  cfg.flr = MIKROBUS( mikrobus, MIKROBUS_INT )
65 
71 #define STEREOAMP_RETVAL uint8_t
72 
73 #define STEREOAMP_OK 0x00
74 #define STEREOAMP_INIT_ERROR 0xFF
75 
81 #define STEREOAMP_I2C_ADDRESS_0 0x7C
82 #define STEREOAMP_I2C_ADDRESS_1 0x7D
83 
89 #define STEREOAMP_CTRL_REG_MODE_CONTROL 0x00
90 #define STEREOAMP_CTRL_REG_DIAGNOSTIC_CONTROL 0x20
91 #define STEREOAMP_CTRL_REG_FAULT_DETECTION 0x40
92 #define STEREOAMP_CTRL_REG_VOLUME_CONTROL1 0x60
93 #define STEREOAMP_CTRL_REG_VOLUME_CONTROL2 0x80
94 
100 #define STEREOAMP_DIAG_REG_FIX_ILIMIT 0x00
101 #define STEREOAMP_DIAG_REG_ILIMIT 0x02
102 #define STEREOAMP_DIAG_REG_DG_RESET 0x04
103 #define STEREOAMP_DIAG_REG_DG_ONE_SHOT 0x00
104 #define STEREOAMP_DIAG_REG_DG_CONT 0x08
105 #define STEREOAMP_DIAG_REG_DG_DISABLE 0x00
106 #define STEREOAMP_DIAG_REG_DG_EN 0x10
107 
113 #define STEREOAMP_MODE_POWER_OFF 0x00
114 #define STEREOAMP_MODE_POWER_ON 0x10
115 #define STEREOAMP_MODE_INPUT1 0x04
116 #define STEREOAMP_MODE_INPUT1_OFF 0x00
117 #define STEREOAMP_MODE_INPUT2 0x08
118 #define STEREOAMP_MODE_INPUT2_OFF 0x00
119 #define STEREOAMP_MODE_BOTH_CHANNELS 0x0C
120 
126 #define STEREOAMP_FLT_DET_REG_OUTPUT_SHT 0x01
127 #define STEREOAMP_FLT_DET_REG_OUTPUT_OPEN 0x02
128 #define STEREOAMP_FLT_DET_REG_RAIL_SHT 0x04
129 #define STEREOAMP_FLT_DET_REG_OVF 0x08
130 #define STEREOAMP_FLT_DET_REG_TSD 0x10
131 
137 #define STEREOAMP_MASK_DATA 0x1F
138 #define STEREOAMP_MASK_ADDR 0xE0
139 #define STEREOAMP_MASK_CHANNEL 0x01
140 
146 #define STEREOAMP_OUTPUT_LEFT_SPEAKER 0x01
147 #define STEREOAMP_OUTPUT_RIGHT_SPEAKER 0x00
148 
154 #define STEREOAMP_GAIN_NEG_80dB 0x00
155 #define STEREOAMP_GAIN_NEG_54dB 0x01
156 #define STEREOAMP_GAIN_NEG_40_5dB 0x02
157 #define STEREOAMP_GAIN_NEG_34_5dB 0x03
158 #define STEREOAMP_GAIN_NEG_30dB 0x04
159 #define STEREOAMP_GAIN_NEG_27dB 0x05
160 #define STEREOAMP_GAIN_NEG_24dB 0x06
161 #define STEREOAMP_GAIN_NEG_21dB 0x07
162 #define STEREOAMP_GAIN_NEG_18dB 0x08
163 #define STEREOAMP_GAIN_NEG_15dB 0x09
164 #define STEREOAMP_GAIN_NEG_13_5dB 0x0A
165 #define STEREOAMP_GAIN_NEG_12dB 0x0B
166 #define STEREOAMP_GAIN_NEG_10_5dB 0x0C
167 #define STEREOAMP_GAIN_NEG_9dB 0x0D
168 #define STEREOAMP_GAIN_NEG_7_5dB 0x0E
169 #define STEREOAMP_GAIN_NEG_6dB 0x0F
170 #define STEREOAMP_GAIN_NEG_4_5dB 0x10
171 #define STEREOAMP_GAIN_NEG_3dB 0x11
172 #define STEREOAMP_GAIN_NEG_1_5dB 0x12
173 #define STEREOAMP_GAIN_NEG_0dB 0x13
174 #define STEREOAMP_GAIN_1_5dB 0x14
175 #define STEREOAMP_GAIN_3dB 0x15
176 #define STEREOAMP_GAIN_4_5dB 0x16
177 #define STEREOAMP_GAIN_6dB 0x17
178 #define STEREOAMP_GAIN_7_5dB 0x18
179 #define STEREOAMP_GAIN_9dB 0x19
180 #define STEREOAMP_GAIN_10_5dB 0x1A
181 #define STEREOAMP_GAIN_12dB 0x1B
182 #define STEREOAMP_GAIN_13_5dB 0x1C
183 #define STEREOAMP_GAIN_15dB 0x1D
184 #define STEREOAMP_GAIN_16_5dB 0x1E
185 #define STEREOAMP_GAIN_18dB 0x1F
186  // End group macro
189 
190 // --------------------------------------------------------------- PUBLIC TYPES
199 typedef struct
200 {
201 
202  // Input pins
203 
204  digital_in_t fll;
205  digital_in_t flr;
206 
207  // Modules
208 
209  i2c_master_t i2c;
210 
211  // ctx variable
212 
215 
216 } stereoamp_t;
217 
221 typedef struct
222 {
223  // Communication gpio pins
224 
225  pin_name_t scl;
226  pin_name_t sda;
227 
228  // Additional gpio pins
229 
230  pin_name_t fll;
231  pin_name_t flr;
232 
233  // static variable
234 
235  uint32_t i2c_speed;
236  uint8_t i2c_address_0;
237  uint8_t i2c_address_1;
238 
240  // End types group
242 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
243 
249 #ifdef __cplusplus
250 extern "C"{
251 #endif
252 
262 
272 
281 
298 void stereoamp_generic_write ( stereoamp_t *ctx, uint8_t ch_addr, uint8_t reg_addr, uint8_t tx_data );
299 
309 void stereoamp_set_volume ( stereoamp_t *ctx, uint8_t volume );
310 
320 
330 
340 
350 
360 
370 
380 
381 #ifdef __cplusplus
382 }
383 #endif
384 #endif // _STEREOAMP_H_
385  // End public_function group
388 
389 // ------------------------------------------------------------------------- END
stereoamp_cfg_t::sda
pin_name_t sda
Definition: stereoamp.h:226
stereoamp_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: stereoamp.h:235
STEREOAMP_RETVAL
#define STEREOAMP_RETVAL
Definition: stereoamp.h:71
stereoamp_init
STEREOAMP_RETVAL stereoamp_init(stereoamp_t *ctx, stereoamp_cfg_t *cfg)
Initialization function.
stereoamp_cfg_t::fll
pin_name_t fll
Definition: stereoamp.h:230
stereoamp_enable_diagnostic
void stereoamp_enable_diagnostic(stereoamp_t *ctx)
Enable the diagnostic function.
stereoamp_cfg_t::i2c_address_0
uint8_t i2c_address_0
Definition: stereoamp.h:236
stereoamp_set_power_on
void stereoamp_set_power_on(stereoamp_t *ctx)
Set the power On by channel function.
stereoamp_mute
void stereoamp_mute(stereoamp_t *ctx)
Set the mute mode function.
stereoamp_t::fll
digital_in_t fll
Definition: stereoamp.h:204
stereoamp_cfg_setup
void stereoamp_cfg_setup(stereoamp_cfg_t *cfg)
Config Object Initialization function.
stereoamp_soft_reset
void stereoamp_soft_reset(stereoamp_t *ctx)
Soft reset function.
stereoamp_cfg_t::i2c_address_1
uint8_t i2c_address_1
Definition: stereoamp.h:237
stereoamp_generic_write
void stereoamp_generic_write(stereoamp_t *ctx, uint8_t ch_addr, uint8_t reg_addr, uint8_t tx_data)
Generic write function.
stereoamp_enable_fault
void stereoamp_enable_fault(stereoamp_t *ctx)
Enable the fault function.
stereoamp_cfg_t
Click configuration structure definition.
Definition: stereoamp.h:222
stereoamp_check_fault_right
uint8_t stereoamp_check_fault_right(stereoamp_t *ctx)
Check the fault of the right speaker function.
stereoamp_check_fault_left
uint8_t stereoamp_check_fault_left(stereoamp_t *ctx)
Check the fault of the left speaker function.
stereoamp_default_cfg
void stereoamp_default_cfg(stereoamp_t *ctx)
Click Default Configuration function.
stereoamp_t::flr
digital_in_t flr
Definition: stereoamp.h:205
stereoamp_t::slave_address_0
uint8_t slave_address_0
Definition: stereoamp.h:213
stereoamp_t
Click ctx object definition.
Definition: stereoamp.h:200
stereoamp_cfg_t::flr
pin_name_t flr
Definition: stereoamp.h:231
stereoamp_set_volume
void stereoamp_set_volume(stereoamp_t *ctx, uint8_t volume)
Set the volume function.
stereoamp_t::slave_address_1
uint8_t slave_address_1
Definition: stereoamp.h:214
stereoamp_cfg_t::scl
pin_name_t scl
Definition: stereoamp.h:225
stereoamp_t::i2c
i2c_master_t i2c
Definition: stereoamp.h:209