c2x20wamp  2.0.0.0
c2x20wamp.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 C2X20WAMP_H
36 #define C2X20WAMP_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 C2X20WAMP_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.shdn = MIKROBUS( mikrobus, MIKROBUS_RST ); \
56  cfg.mute = MIKROBUS( mikrobus, MIKROBUS_CS ); \
57  cfg.addr1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
58  cfg.addr2 = MIKROBUS( mikrobus, MIKROBUS_INT );
59 
65 #define C2X20WAMP_RETVAL uint8_t
66 
67 #define C2X20WAMP_OK 0x00
68 #define C2X20WAMP_INIT_ERROR 0xFF
69 
75 #define C2X20WAMP_I2C_ADDRESS 0x48
76 
82 #define C2X20WAMP_ADDRESS_1 0x01
83 #define C2X20WAMP_ADDRESS_2 0x02
84 
90 #define C2X20WAMP_6_BIT_VALUE 0x3F
91 #define C2X20WAMP_CMD_VOLUME_UP 0xC4
92 #define C2X20WAMP_CMD_VOLUME_DOWN 0xC5
93 #define C2X20WAMP_CMD_FILTERLESS_MODULATION 0x40
94 #define C2X20WAMP_CMD_CLASSIC_PWM_MODULATION 0x41
95 
101 #define C2X20WAMP_6_BIT_VALUE 0x3F
102  // End group macro
105 // --------------------------------------------------------------- PUBLIC TYPES
114 typedef struct
115 {
116  // Output pins
117 
118  digital_out_t shdn;
119  digital_out_t mute;
120 
121  // Input pins
122 
123  digital_in_t addr1;
124  digital_in_t addr2;
125 
126  // Modules
127 
128  i2c_master_t i2c;
129 
130  // ctx variable
131 
132  uint8_t slave_address;
133 
134 } c2x20wamp_t;
135 
139 typedef struct
140 {
141  // Communication gpio pins
142 
143  pin_name_t scl;
144  pin_name_t sda;
145 
146  // Additional gpio pins
147 
148  pin_name_t shdn;
149  pin_name_t mute;
150  pin_name_t addr1;
151  pin_name_t addr2;
152 
153  // static variable
154 
155  uint32_t i2c_speed;
156  uint8_t i2c_address;
157 
159  // End types group
161 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
162 
168 #ifdef __cplusplus
169 extern "C"{
170 #endif
171 
181 
190 
199 void c2x20wamp_generic_write ( c2x20wamp_t *ctx, uint8_t data_buf );
200 
201 
210 void c2x20wamp_mode_play( c2x20wamp_t *ctx );
211 
220 void c2x20wamp_mode_mute( c2x20wamp_t *ctx );
221 
230 void c2x20wamp_disable( c2x20wamp_t *ctx );
231 
240 void c2x20wamp_enable( c2x20wamp_t *ctx );
241 
255 void c2x20wamp_set_volume( c2x20wamp_t *ctx, uint8_t volume );
256 
264 void c2x20wamp_volume_up( c2x20wamp_t *ctx );
265 
276 
287 
298 
299 #ifdef __cplusplus
300 }
301 #endif
302 #endif // _C2X20WAMP_H_
303  // End public_function group
306 
307 // ------------------------------------------------------------------------- END
void c2x20wamp_disable(c2x20wamp_t *ctx)
Disable the amplifier function.
void c2x20wamp_set_volume(c2x20wamp_t *ctx, uint8_t volume)
Set volume of the amplifier function.
#define C2X20WAMP_RETVAL
Definition: c2x20wamp.h:65
uint32_t i2c_speed
Definition: c2x20wamp.h:155
uint8_t slave_address
Definition: c2x20wamp.h:132
void c2x20wamp_volume_up(c2x20wamp_t *ctx)
Increase the volume by one level function.
digital_in_t addr2
Definition: c2x20wamp.h:124
pin_name_t scl
Definition: c2x20wamp.h:143
pin_name_t addr1
Definition: c2x20wamp.h:150
uint8_t i2c_address
Definition: c2x20wamp.h:156
pin_name_t addr2
Definition: c2x20wamp.h:151
i2c_master_t i2c
Definition: c2x20wamp.h:128
digital_in_t addr1
Definition: c2x20wamp.h:123
void c2x20wamp_filterless_modulation(c2x20wamp_t *ctx)
Set filterless output modulation function.
pin_name_t mute
Definition: c2x20wamp.h:149
Click configuration structure definition.
Definition: c2x20wamp.h:139
C2X20WAMP_RETVAL c2x20wamp_init(c2x20wamp_t *ctx, c2x20wamp_cfg_t *cfg)
Initialization function.
void c2x20wamp_generic_write(c2x20wamp_t *ctx, uint8_t data_buf)
Generic write function.
digital_out_t mute
Definition: c2x20wamp.h:119
Click ctx object definition.
Definition: c2x20wamp.h:114
digital_out_t shdn
Definition: c2x20wamp.h:118
pin_name_t sda
Definition: c2x20wamp.h:144
void c2x20wamp_mode_play(c2x20wamp_t *ctx)
Set Play mode of the amplifier function.
void c2x20wamp_volume_down(c2x20wamp_t *ctx)
Decrease the volume by one level function.
void c2x20wamp_classic_pwm_modulation(c2x20wamp_t *ctx)
Set classic PWM output modulation function.
pin_name_t shdn
Definition: c2x20wamp.h:148
void c2x20wamp_cfg_setup(c2x20wamp_cfg_t *cfg)
Config Object Initialization function.
void c2x20wamp_mode_mute(c2x20wamp_t *ctx)
Set Mute mode of the amplifier function.
void c2x20wamp_enable(c2x20wamp_t *ctx)
Enable the amplifier function.