buzz3  2.0.0.0
buzz3.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef BUZZ3_H
29 #define BUZZ3_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_pwm.h"
38 
59 #define BUZZ3_DEF_FREQ 500
60 
65 #define BUZZ3_NOTE_C2 65
66 #define BUZZ3_NOTE_Db2 69
67 #define BUZZ3_NOTE_D2 73
68 #define BUZZ3_NOTE_Eb2 78
69 #define BUZZ3_NOTE_E2 82
70 #define BUZZ3_NOTE_F2 87
71 #define BUZZ3_NOTE_Gb2 93
72 #define BUZZ3_NOTE_G2 98
73 #define BUZZ3_NOTE_Ab2 104
74 #define BUZZ3_NOTE_A2 110
75 #define BUZZ3_NOTE_Bb2 117
76 #define BUZZ3_NOTE_B2 123
77 #define BUZZ3_NOTE_C3 131
78 #define BUZZ3_NOTE_Db3 139
79 #define BUZZ3_NOTE_D3 147
80 #define BUZZ3_NOTE_Eb3 156
81 #define BUZZ3_NOTE_E3 165
82 #define BUZZ3_NOTE_F3 175
83 #define BUZZ3_NOTE_Gb3 185
84 #define BUZZ3_NOTE_G3 196
85 #define BUZZ3_NOTE_Ab3 208
86 #define BUZZ3_NOTE_A3 220
87 #define BUZZ3_NOTE_AS3 233
88 #define BUZZ3_NOTE_B3 247
89 #define BUZZ3_NOTE_C4 262
90 #define BUZZ3_NOTE_Db4 277
91 #define BUZZ3_NOTE_D4 294
92 #define BUZZ3_NOTE_Eb4 311
93 #define BUZZ3_NOTE_E4 330
94 #define BUZZ3_NOTE_F4 349
95 #define BUZZ3_NOTE_Gb4 370
96 #define BUZZ3_NOTE_G4 392
97 #define BUZZ3_NOTE_Ab4 415
98 #define BUZZ3_NOTE_A4 440
99 #define BUZZ3_NOTE_Bb4 466
100 #define BUZZ3_NOTE_B4 494
101 #define BUZZ3_NOTE_C5 523
102 #define BUZZ3_NOTE_Db5 554
103 #define BUZZ3_NOTE_D5 587
104 #define BUZZ3_NOTE_Eb5 622
105 #define BUZZ3_NOTE_E5 659
106 #define BUZZ3_NOTE_F5 698
107 #define BUZZ3_NOTE_Gb5 740
108 #define BUZZ3_NOTE_G5 784
109 #define BUZZ3_NOTE_Ab5 831
110 #define BUZZ3_NOTE_A5 880
111 #define BUZZ3_NOTE_Bb5 932
112 #define BUZZ3_NOTE_B5 988
113 #define BUZZ3_NOTE_C6 1047
114 #define BUZZ3_NOTE_Db6 1109
115 #define BUZZ3_NOTE_D6 1175
116 #define BUZZ3_NOTE_Eb6 1245
117 #define BUZZ3_NOTE_E6 1319
118 #define BUZZ3_NOTE_F6 1397
119 #define BUZZ3_NOTE_Gb6 1480
120 #define BUZZ3_NOTE_G6 1568
121 #define BUZZ3_NOTE_Ab6 1661
122 #define BUZZ3_NOTE_A6 1760
123 #define BUZZ3_NOTE_Bb6 1865
124 #define BUZZ3_NOTE_B6 1976
125 #define BUZZ3_NOTE_C7 2093
126 #define BUZZ3_NOTE_Db7 2217
127 #define BUZZ3_NOTE_D7 2349
128 #define BUZZ3_NOTE_Eb7 2489
129 #define BUZZ3_NOTE_E7 2637
130 #define BUZZ3_NOTE_F7 2794
131 #define BUZZ3_NOTE_Gb7 2960
132 #define BUZZ3_NOTE_G7 3136
133 #define BUZZ3_NOTE_Ab7 3322
134 #define BUZZ3_NOTE_A7 3520
135 #define BUZZ3_NOTE_Bb7 3729
136 #define BUZZ3_NOTE_B7 3951
137 #define BUZZ3_NOTE_C8 4186
138 #define BUZZ3_NOTE_Db8 4435
139 #define BUZZ3_NOTE_D8 4699
140 #define BUZZ3_NOTE_Eb8 4978
141 
146 #define BUZZ3_OP_MODE_GAIN_x0 0x00
147 #define BUZZ3_OP_MODE_GAIN_x1 0x01
148 #define BUZZ3_OP_MODE_GAIN_x2 0x02
149 #define BUZZ3_OP_MODE_GAIN_x3 0x03
150  // buzz3_cfg
152 
167 #define BUZZ3_MAP_MIKROBUS( cfg, mikrobus ) \
168  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
169  cfg.en1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
170  cfg.en2 = MIKROBUS( mikrobus, MIKROBUS_RST )
171  // buzz3_map // buzz3
174 
184 typedef struct
185 {
186  // Output pins
187  digital_out_t en1;
188  digital_out_t en2;
190  // Modules
191  pwm_t pwm;
193  // ctx variable
194  uint32_t pwm_freq;
196 } buzz3_t;
197 
202 typedef struct
203 {
204  // Communication gpio pins
205  pin_name_t pwm;
207  // Additional gpio pins
208  pin_name_t en1;
209  pin_name_t en2;
211  // Static variable
212  uint32_t dev_pwm_freq;
214 } buzz3_cfg_t;
215 
220 typedef enum
221 {
222  BUZZ3_OK = 0,
223  BUZZ3_ERROR = -1
224 
226 
243 
257 err_t buzz3_init ( buzz3_t *ctx, buzz3_cfg_t *cfg );
258 
272 err_t buzz3_default_cfg ( buzz3_t *ctx );
273 
285 err_t buzz3_set_duty_cycle ( buzz3_t *ctx, float duty_cycle );
286 
297 err_t buzz3_pwm_stop ( buzz3_t *ctx );
298 
309 err_t buzz3_pwm_start ( buzz3_t *ctx );
310 
323 err_t buzz3_set_gain_operating_mode ( buzz3_t *ctx, uint8_t op_mode );
324 
333 void buzz3_play_sound ( buzz3_t *ctx, uint16_t freq, uint16_t duration );
334 
335 #ifdef __cplusplus
336 }
337 #endif
338 #endif // BUZZ3_H
339  // buzz3
341 
342 // ------------------------------------------------------------------------ END
buzz3_set_gain_operating_mode
err_t buzz3_set_gain_operating_mode(buzz3_t *ctx, uint8_t op_mode)
Buzz 3 set gain operating mode function.
buzz3_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: buzz3.h:212
buzz3_play_sound
void buzz3_play_sound(buzz3_t *ctx, uint16_t freq, uint16_t duration)
Buzz 3 play sound function.
buzz3_return_value_t
buzz3_return_value_t
Buzz 3 Click return value data.
Definition: buzz3.h:221
buzz3_set_duty_cycle
err_t buzz3_set_duty_cycle(buzz3_t *ctx, float duty_cycle)
Buzz 3 sets PWM duty cycle.
buzz3_init
err_t buzz3_init(buzz3_t *ctx, buzz3_cfg_t *cfg)
Buzz 3 initialization function.
buzz3_pwm_stop
err_t buzz3_pwm_stop(buzz3_t *ctx)
Buzz 3 stop PWM module.
buzz3_default_cfg
err_t buzz3_default_cfg(buzz3_t *ctx)
Buzz 3 default configuration function.
buzz3_t::pwm_freq
uint32_t pwm_freq
Definition: buzz3.h:194
buzz3_t
Buzz 3 Click driver selector.
Definition: buzz3.h:185
buzz3_t::en2
digital_out_t en2
Definition: buzz3.h:188
buzz3_cfg_t::en2
pin_name_t en2
Definition: buzz3.h:209
buzz3_t::en1
digital_out_t en1
Definition: buzz3.h:187
buzz3_pwm_start
err_t buzz3_pwm_start(buzz3_t *ctx)
Buzz 3 start PWM module.
buzz3_cfg_t::en1
pin_name_t en1
Definition: buzz3.h:208
buzz3_cfg_t
Buzz 3 Click configuration object.
Definition: buzz3.h:203
buzz3_cfg_t::pwm
pin_name_t pwm
Definition: buzz3.h:205
buzz3_t::pwm
pwm_t pwm
Definition: buzz3.h:191
BUZZ3_ERROR
@ BUZZ3_ERROR
Definition: buzz3.h:223
BUZZ3_OK
@ BUZZ3_OK
Definition: buzz3.h:222
buzz3_cfg_setup
void buzz3_cfg_setup(buzz3_cfg_t *cfg)
Buzz 3 configuration object setup function.