evc  2.0.0.0
evc.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 EVC_H
36 #define EVC_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 EVC_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
65 
71 #define EVC_RETVAL uint8_t
72 
73 #define EVC_OK 0x00
74 #define EVC_INIT_ERROR 0xFF
75 
81 #define EVC_SET_VOLUME_1dB 0x11
82 #define EVC_SET_VOLUME_10dB 0x01
83 #define EVC_SET_VOLUME_20dB 0x02
84 #define EVC_SET_VOLUME_2dB 0x12
85 #define EVC_SET_VOLUME_30dB 0x03
86 #define EVC_SET_VOLUME_3dB 0x13
87 #define EVC_SET_VOLUME_40dB 0x04
88 #define EVC_SET_VOLUME_4dB 0x14
89 #define EVC_SET_VOLUME_50dB 0x05
90 #define EVC_SET_VOLUME_5dB 0x15
91 #define EVC_SET_VOLUME_60dB 0x06
92 #define EVC_SET_VOLUME_6dB 0x16
93 #define EVC_SET_VOLUME_70dB 0x07
94 #define EVC_SET_VOLUME_7dB 0x17
95 #define EVC_SET_VOLUME_0dB 0x00
96 #define EVC_SET_VOLUME_8dB 0x18
97 #define EVC_SET_VOLUME_9dB 0x19
98 
104 #define EVC_CHANNEL_1 0x80
105 #define EVC_CHANNEL_2 0x40
106 #define EVC_CHANNEL_3 0x00
107 #define EVC_CHANNEL_4 0x20
108 #define EVC_CHANNEL_5 0x60
109 #define EVC_CHANNEL_6 0xA0
110 #define EVC_ALL_CHANNEL 0xC0
111 
117 #define EVC_ALL_CHANNEL_MUTE 0xF9
118 #define EVC_ALL_CHANNEL_UNMUTE 0xF8
119 
125 #define EVC_CLEAR_ALL 0xC0
126 
132 #define EVC_DEVICE_SLAVE_ADDRESS_01 0x42
133 #define EVC_DEVICE_SLAVE_ADDRESS_00 0x40
134 #define EVC_DEVICE_SLAVE_ADDRESS_10 0x44
135 #define EVC_DEVICE_SLAVE_ADDRESS_11 0x46
136  // End group macro
139 // --------------------------------------------------------------- PUBLIC TYPES
148 typedef struct
149 {
150  // Modules
151 
152  i2c_master_t i2c;
153 
154  // ctx variable
155 
156  uint8_t slave_address;
157  uint8_t mute_flag;
158  uint8_t play_flag;
159  int8_t volume;
160  uint8_t channel;
161  uint8_t test_flag;
162 
163 } evc_t;
164 
168 typedef struct
169 {
170  // Communication gpio pins
171 
172  pin_name_t scl;
173  pin_name_t sda;
174 
175  // static variable
176 
177  uint32_t i2c_speed;
178  uint8_t i2c_address;
179  uint8_t mute_cfg_flag;
180  uint8_t play_cfg_flag;
181  int8_t cfg_volume;
182  uint8_t cfg_channel;
183  uint8_t test_cfg_flag;
184 
185 } evc_cfg_t;
186  // End types group
188 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
189 
195 #ifdef __cplusplus
196 extern "C"{
197 #endif
198 
207 void evc_cfg_setup ( evc_cfg_t *cfg );
208 
218 
228 void evc_default_cfg ( evc_t *ctx );
229 
240 void evc_generic_write ( evc_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
241 
252 void evc_generic_read ( evc_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
253 
264 void evc_set_volume_part ( evc_t *ctx, uint8_t channel, uint8_t volume1, uint8_t volume2 );
265 
275 void evc_set_volume_full ( evc_t *ctx, uint8_t channel, int8_t volume );
276 
288 void evc_clear ( evc_t *ctx );
289 
298 void evc_mute ( evc_t *ctx, uint8_t mute );
299 
300 #ifdef __cplusplus
301 }
302 #endif
303 #endif // _EVC_H_
304  // End public_function group
307 
308 // ------------------------------------------------------------------------- END
evc_cfg_t
Click configuration structure definition.
Definition: evc.h:169
evc_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: evc.h:177
evc_cfg_t::sda
pin_name_t sda
Definition: evc.h:173
evc_t
Click ctx object definition.
Definition: evc.h:149
mute
void mute(evc_t *ctx)
Definition: main.c:84
evc_generic_write
void evc_generic_write(evc_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
evc_t::mute_flag
uint8_t mute_flag
Definition: evc.h:157
evc_init
EVC_RETVAL evc_init(evc_t *ctx, evc_cfg_t *cfg)
Initialization function.
evc_cfg_t::scl
pin_name_t scl
Definition: evc.h:172
evc_cfg_t::play_cfg_flag
uint8_t play_cfg_flag
Definition: evc.h:180
evc_t::slave_address
uint8_t slave_address
Definition: evc.h:156
evc_cfg_t::mute_cfg_flag
uint8_t mute_cfg_flag
Definition: evc.h:179
evc_set_volume_part
void evc_set_volume_part(evc_t *ctx, uint8_t channel, uint8_t volume1, uint8_t volume2)
Set volume for the channel.
evc_cfg_t::test_cfg_flag
uint8_t test_cfg_flag
Definition: evc.h:183
evc_t::play_flag
uint8_t play_flag
Definition: evc.h:158
evc_t::volume
int8_t volume
Definition: evc.h:159
evc_cfg_t::cfg_volume
int8_t cfg_volume
Definition: evc.h:181
evc_cfg_t::i2c_address
uint8_t i2c_address
Definition: evc.h:178
EVC_RETVAL
#define EVC_RETVAL
Definition: evc.h:71
evc_t::i2c
i2c_master_t i2c
Definition: evc.h:152
evc_set_volume_full
void evc_set_volume_full(evc_t *ctx, uint8_t channel, int8_t volume)
Set volume for the channel.
evc_generic_read
void evc_generic_read(evc_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
evc_t::channel
uint8_t channel
Definition: evc.h:160
evc_default_cfg
void evc_default_cfg(evc_t *ctx)
Click Default Configuration function.
evc_cfg_t::cfg_channel
uint8_t cfg_channel
Definition: evc.h:182
evc_cfg_setup
void evc_cfg_setup(evc_cfg_t *cfg)
Config Object Initialization function.
evc_clear
void evc_clear(evc_t *ctx)
Clear register.
evc_mute
void evc_mute(evc_t *ctx, uint8_t mute)
Mute and Unmute.
evc_t::test_flag
uint8_t test_flag
Definition: evc.h:161