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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define EVC_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
55 
61 #define EVC_RETVAL uint8_t
62 
63 #define EVC_OK 0x00
64 #define EVC_INIT_ERROR 0xFF
65 
71 #define EVC_SET_VOLUME_1dB 0x11
72 #define EVC_SET_VOLUME_10dB 0x01
73 #define EVC_SET_VOLUME_20dB 0x02
74 #define EVC_SET_VOLUME_2dB 0x12
75 #define EVC_SET_VOLUME_30dB 0x03
76 #define EVC_SET_VOLUME_3dB 0x13
77 #define EVC_SET_VOLUME_40dB 0x04
78 #define EVC_SET_VOLUME_4dB 0x14
79 #define EVC_SET_VOLUME_50dB 0x05
80 #define EVC_SET_VOLUME_5dB 0x15
81 #define EVC_SET_VOLUME_60dB 0x06
82 #define EVC_SET_VOLUME_6dB 0x16
83 #define EVC_SET_VOLUME_70dB 0x07
84 #define EVC_SET_VOLUME_7dB 0x17
85 #define EVC_SET_VOLUME_0dB 0x00
86 #define EVC_SET_VOLUME_8dB 0x18
87 #define EVC_SET_VOLUME_9dB 0x19
88 
94 #define EVC_CHANNEL_1 0x80
95 #define EVC_CHANNEL_2 0x40
96 #define EVC_CHANNEL_3 0x00
97 #define EVC_CHANNEL_4 0x20
98 #define EVC_CHANNEL_5 0x60
99 #define EVC_CHANNEL_6 0xA0
100 #define EVC_ALL_CHANNEL 0xC0
101 
107 #define EVC_ALL_CHANNEL_MUTE 0xF9
108 #define EVC_ALL_CHANNEL_UNMUTE 0xF8
109 
115 #define EVC_CLEAR_ALL 0xC0
116 
122 #define EVC_DEVICE_SLAVE_ADDRESS_01 0x42
123 #define EVC_DEVICE_SLAVE_ADDRESS_00 0x40
124 #define EVC_DEVICE_SLAVE_ADDRESS_10 0x44
125 #define EVC_DEVICE_SLAVE_ADDRESS_11 0x46
126  // End group macro
129 // --------------------------------------------------------------- PUBLIC TYPES
138 typedef struct
139 {
140  // Modules
141 
142  i2c_master_t i2c;
143 
144  // ctx variable
145 
146  uint8_t slave_address;
147  uint8_t mute_flag;
148  uint8_t play_flag;
149  int8_t volume;
150  uint8_t channel;
151  uint8_t test_flag;
152 
153 } evc_t;
154 
158 typedef struct
159 {
160  // Communication gpio pins
161 
162  pin_name_t scl;
163  pin_name_t sda;
164 
165  // static variable
166 
167  uint32_t i2c_speed;
168  uint8_t i2c_address;
169  uint8_t mute_cfg_flag;
170  uint8_t play_cfg_flag;
171  int8_t cfg_volume;
172  uint8_t cfg_channel;
173  uint8_t test_cfg_flag;
174 
175 } evc_cfg_t;
176  // End types group
178 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
179 
185 #ifdef __cplusplus
186 extern "C"{
187 #endif
188 
197 void evc_cfg_setup ( evc_cfg_t *cfg );
198 
208 
218 void evc_default_cfg ( evc_t *ctx );
219 
230 void evc_generic_write ( evc_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
231 
242 void evc_generic_read ( evc_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
243 
254 void evc_set_volume_part ( evc_t *ctx, uint8_t channel, uint8_t volume1, uint8_t volume2 );
255 
265 void evc_set_volume_full ( evc_t *ctx, uint8_t channel, int8_t volume );
266 
278 void evc_clear ( evc_t *ctx );
279 
288 void evc_mute ( evc_t *ctx, uint8_t mute );
289 
290 #ifdef __cplusplus
291 }
292 #endif
293 #endif // _EVC_H_
294  // End public_function group
297 
298 // ------------------------------------------------------------------------- END
evc_cfg_t
Click configuration structure definition.
Definition: evc.h:159
evc_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: evc.h:167
evc_cfg_t::sda
pin_name_t sda
Definition: evc.h:163
evc_t
Click ctx object definition.
Definition: evc.h:139
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:147
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:162
evc_cfg_t::play_cfg_flag
uint8_t play_cfg_flag
Definition: evc.h:170
evc_t::slave_address
uint8_t slave_address
Definition: evc.h:146
evc_cfg_t::mute_cfg_flag
uint8_t mute_cfg_flag
Definition: evc.h:169
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:173
evc_t::play_flag
uint8_t play_flag
Definition: evc.h:148
evc_t::volume
int8_t volume
Definition: evc.h:149
evc_cfg_t::cfg_volume
int8_t cfg_volume
Definition: evc.h:171
evc_cfg_t::i2c_address
uint8_t i2c_address
Definition: evc.h:168
EVC_RETVAL
#define EVC_RETVAL
Definition: evc.h:61
evc_t::i2c
i2c_master_t i2c
Definition: evc.h:142
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:150
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:172
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:151