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_i2c_master.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define C2X20WAMP_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
53  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
54  cfg.shdn = MIKROBUS( mikrobus, MIKROBUS_RST ); \
55  cfg.mute = MIKROBUS( mikrobus, MIKROBUS_CS ); \
56  cfg.addr1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
57  cfg.addr2 = MIKROBUS( mikrobus, MIKROBUS_INT );
58 
64 #define C2X20WAMP_RETVAL int8_t
65 
66 #define C2X20WAMP_OK 0
67 #define C2X20WAMP_INIT_ERROR (-1)
68 
74 #define C2X20WAMP_I2C_ADDRESS 0x48
75 
81 #define C2X20WAMP_ADDRESS_1 0x01
82 #define C2X20WAMP_ADDRESS_2 0x02
83 
89 #define C2X20WAMP_6_BIT_VALUE 0x3F
90 #define C2X20WAMP_CMD_VOLUME_UP 0xC4
91 #define C2X20WAMP_CMD_VOLUME_DOWN 0xC5
92 #define C2X20WAMP_CMD_FILTERLESS_MODULATION 0x40
93 #define C2X20WAMP_CMD_CLASSIC_PWM_MODULATION 0x41
94 
100 #define C2X20WAMP_6_BIT_VALUE 0x3F
101  // End group macro
104 // --------------------------------------------------------------- PUBLIC TYPES
113 typedef struct
114 {
115  // Output pins
116 
117  digital_out_t shdn;
118  digital_out_t mute;
119 
120  // Input pins
121 
122  digital_out_t addr1;
123  digital_out_t addr2;
124 
125  // Modules
126 
127  i2c_master_t i2c;
128 
129  // ctx variable
130 
131  uint8_t slave_address;
132 
133 } c2x20wamp_t;
134 
138 typedef struct
139 {
140  // Communication gpio pins
141 
142  pin_name_t scl;
143  pin_name_t sda;
144 
145  // Additional gpio pins
146 
147  pin_name_t shdn;
148  pin_name_t mute;
149  pin_name_t addr1;
150  pin_name_t addr2;
151 
152  // static variable
153 
154  uint32_t i2c_speed;
155  uint8_t i2c_address;
156 
158  // End types group
160 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
161 
167 #ifdef __cplusplus
168 extern "C"{
169 #endif
170 
180 
189 
198 void c2x20wamp_generic_write ( c2x20wamp_t *ctx, uint8_t data_buf );
199 
200 
209 void c2x20wamp_mode_play( c2x20wamp_t *ctx );
210 
219 void c2x20wamp_mode_mute( c2x20wamp_t *ctx );
220 
229 void c2x20wamp_disable( c2x20wamp_t *ctx );
230 
239 void c2x20wamp_enable( c2x20wamp_t *ctx );
240 
254 void c2x20wamp_set_volume( c2x20wamp_t *ctx, uint8_t volume );
255 
263 void c2x20wamp_volume_up( c2x20wamp_t *ctx );
264 
275 
286 
297 
298 #ifdef __cplusplus
299 }
300 #endif
301 #endif // C2X20WAMP_H
302  // End public_function group // End click Driver group
305 
306 // ------------------------------------------------------------------------ END
c2x20wamp_classic_pwm_modulation
void c2x20wamp_classic_pwm_modulation(c2x20wamp_t *ctx)
Set classic PWM output modulation function.
c2x20wamp_set_volume
void c2x20wamp_set_volume(c2x20wamp_t *ctx, uint8_t volume)
Set volume of the amplifier function.
c2x20wamp_generic_write
void c2x20wamp_generic_write(c2x20wamp_t *ctx, uint8_t data_buf)
Generic write function.
c2x20wamp_volume_up
void c2x20wamp_volume_up(c2x20wamp_t *ctx)
Increase the volume by one level function.
c2x20wamp_init
C2X20WAMP_RETVAL c2x20wamp_init(c2x20wamp_t *ctx, c2x20wamp_cfg_t *cfg)
Initialization function.
c2x20wamp_mode_mute
void c2x20wamp_mode_mute(c2x20wamp_t *ctx)
Set Mute mode of the amplifier function.
c2x20wamp_cfg_t
Click configuration structure definition.
Definition: c2x20wamp.h:138
c2x20wamp_t
Click ctx object definition.
Definition: c2x20wamp.h:113
c2x20wamp_cfg_t::shdn
pin_name_t shdn
Definition: c2x20wamp.h:147
c2x20wamp_enable
void c2x20wamp_enable(c2x20wamp_t *ctx)
Enable the amplifier function.
c2x20wamp_cfg_t::scl
pin_name_t scl
Definition: c2x20wamp.h:142
c2x20wamp_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c2x20wamp.h:154
c2x20wamp_cfg_t::i2c_address
uint8_t i2c_address
Definition: c2x20wamp.h:155
c2x20wamp_t::slave_address
uint8_t slave_address
Definition: c2x20wamp.h:131
C2X20WAMP_RETVAL
#define C2X20WAMP_RETVAL
Definition: c2x20wamp.h:64
c2x20wamp_cfg_t::mute
pin_name_t mute
Definition: c2x20wamp.h:148
c2x20wamp_t::i2c
i2c_master_t i2c
Definition: c2x20wamp.h:127
c2x20wamp_cfg_t::sda
pin_name_t sda
Definition: c2x20wamp.h:143
c2x20wamp_filterless_modulation
void c2x20wamp_filterless_modulation(c2x20wamp_t *ctx)
Set filterless output modulation function.
c2x20wamp_volume_down
void c2x20wamp_volume_down(c2x20wamp_t *ctx)
Decrease the volume by one level function.
c2x20wamp_t::addr1
digital_out_t addr1
Definition: c2x20wamp.h:122
c2x20wamp_t::shdn
digital_out_t shdn
Definition: c2x20wamp.h:117
c2x20wamp_t::addr2
digital_out_t addr2
Definition: c2x20wamp.h:123
c2x20wamp_mode_play
void c2x20wamp_mode_play(c2x20wamp_t *ctx)
Set Play mode of the amplifier function.
c2x20wamp_disable
void c2x20wamp_disable(c2x20wamp_t *ctx)
Disable the amplifier function.
c2x20wamp_t::mute
digital_out_t mute
Definition: c2x20wamp.h:118
c2x20wamp_cfg_t::addr1
pin_name_t addr1
Definition: c2x20wamp.h:149
c2x20wamp_cfg_t::addr2
pin_name_t addr2
Definition: c2x20wamp.h:150
c2x20wamp_cfg_setup
void c2x20wamp_cfg_setup(c2x20wamp_cfg_t *cfg)
Config Object Initialization function.