buzz  2.0.0.0
buzz.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 BUZZ_H
29 #define BUZZ_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 BUZZ_DEF_FREQ 5000
60  // buzz_cfg
62 
72 #define BUZZ_NOTE_C2 65
73 #define BUZZ_NOTE_Db2 69
74 #define BUZZ_NOTE_D2 73
75 #define BUZZ_NOTE_Eb2 78
76 #define BUZZ_NOTE_E2 82
77 #define BUZZ_NOTE_F2 87
78 #define BUZZ_NOTE_Gb2 93
79 #define BUZZ_NOTE_G2 98
80 #define BUZZ_NOTE_Ab2 104
81 #define BUZZ_NOTE_A2 110
82 #define BUZZ_NOTE_Bb2 117
83 #define BUZZ_NOTE_B2 123
84 #define BUZZ_NOTE_C3 131
85 #define BUZZ_NOTE_Db3 139
86 #define BUZZ_NOTE_D3 147
87 #define BUZZ_NOTE_Eb3 156
88 #define BUZZ_NOTE_E3 165
89 #define BUZZ_NOTE_F3 175
90 #define BUZZ_NOTE_Gb3 185
91 #define BUZZ_NOTE_G3 196
92 #define BUZZ_NOTE_Ab3 208
93 #define BUZZ_NOTE_A3 220
94 #define BUZZ_NOTE_AS3 233
95 #define BUZZ_NOTE_B3 247
96 #define BUZZ_NOTE_C4 262
97 #define BUZZ_NOTE_Db4 277
98 #define BUZZ_NOTE_D4 294
99 #define BUZZ_NOTE_Eb4 311
100 #define BUZZ_NOTE_E4 330
101 #define BUZZ_NOTE_F4 349
102 #define BUZZ_NOTE_Gb4 370
103 #define BUZZ_NOTE_G4 392
104 #define BUZZ_NOTE_Ab4 415
105 #define BUZZ_NOTE_A4 440
106 #define BUZZ_NOTE_Bb4 466
107 #define BUZZ_NOTE_B4 494
108 #define BUZZ_NOTE_C5 523
109 #define BUZZ_NOTE_Db5 554
110 #define BUZZ_NOTE_D5 587
111 #define BUZZ_NOTE_Eb5 622
112 #define BUZZ_NOTE_E5 659
113 #define BUZZ_NOTE_F5 698
114 #define BUZZ_NOTE_Gb5 740
115 #define BUZZ_NOTE_G5 784
116 #define BUZZ_NOTE_Ab5 831
117 #define BUZZ_NOTE_A5 880
118 #define BUZZ_NOTE_Bb5 932
119 #define BUZZ_NOTE_B5 988
120 #define BUZZ_NOTE_C6 1047
121 #define BUZZ_NOTE_Db6 1109
122 #define BUZZ_NOTE_D6 1175
123 #define BUZZ_NOTE_Eb6 1245
124 #define BUZZ_NOTE_E6 1319
125 #define BUZZ_NOTE_F6 1397
126 #define BUZZ_NOTE_Gb6 1480
127 #define BUZZ_NOTE_G6 1568
128 #define BUZZ_NOTE_Ab6 1661
129 #define BUZZ_NOTE_A6 1760
130 #define BUZZ_NOTE_Bb6 1865
131 #define BUZZ_NOTE_B6 1976
132 #define BUZZ_NOTE_C7 2093
133 #define BUZZ_NOTE_Db7 2217
134 #define BUZZ_NOTE_D7 2349
135 #define BUZZ_NOTE_Eb7 2489
136 #define BUZZ_NOTE_E7 2637
137 #define BUZZ_NOTE_F7 2794
138 #define BUZZ_NOTE_Gb7 2960
139 #define BUZZ_NOTE_G7 3136
140 #define BUZZ_NOTE_Ab7 3322
141 #define BUZZ_NOTE_A7 3520
142 #define BUZZ_NOTE_Bb7 3729
143 #define BUZZ_NOTE_B7 3951
144 #define BUZZ_NOTE_C8 4186
145 #define BUZZ_NOTE_Db8 4435
146 #define BUZZ_NOTE_D8 4699
147 #define BUZZ_NOTE_Eb8 4978
148  // buzz_freq
150 
167 #define BUZZ_MAP_MIKROBUS( cfg, mikrobus ) \
168  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
169  // buzz_map // buzz
172 
182 typedef struct
183 {
184  // Modules
185 
186  pwm_t pwm;
188  // ctx variable
189 
190  uint32_t pwm_freq;
192 } buzz_t;
193 
198 typedef struct
199 {
200  // Communication gpio pins
201 
202  pin_name_t pwm;
204  // Static variable
205 
206  uint32_t dev_pwm_freq;
208 } buzz_cfg_t;
209 
214 typedef enum
215 {
216  BUZZ_OK = 0,
217  BUZZ_ERROR = -1
218 
220 
237 
252 err_t buzz_init ( buzz_t *ctx, buzz_cfg_t *cfg );
253 
266 err_t buzz_set_duty_cycle ( buzz_t *ctx, float duty_cycle );
267 
279 err_t buzz_pwm_stop ( buzz_t *ctx );
280 
292 err_t buzz_pwm_start ( buzz_t *ctx );
293 
306 void buzz_play_sound ( buzz_t *ctx, uint16_t freq, uint16_t level, uint16_t duration );
307 
308 #ifdef __cplusplus
309 }
310 #endif
311 #endif // BUZZ_H
312  // buzz
314 
315 // ------------------------------------------------------------------------ END
buzz_cfg_t
BUZZ Click configuration object.
Definition: buzz.h:199
buzz_cfg_setup
void buzz_cfg_setup(buzz_cfg_t *cfg)
BUZZ configuration object setup function.
buzz_return_value_t
buzz_return_value_t
BUZZ Click return value data.
Definition: buzz.h:215
buzz_t
BUZZ Click driver selector.
Definition: buzz.h:183
buzz_t::pwm_freq
uint32_t pwm_freq
Definition: buzz.h:190
buzz_pwm_start
err_t buzz_pwm_start(buzz_t *ctx)
BUZZ start PWM module.
buzz_play_sound
void buzz_play_sound(buzz_t *ctx, uint16_t freq, uint16_t level, uint16_t duration)
BUZZ Play sound function.
BUZZ_OK
@ BUZZ_OK
Definition: buzz.h:216
buzz_pwm_stop
err_t buzz_pwm_stop(buzz_t *ctx)
BUZZ stop PWM module.
buzz_set_duty_cycle
err_t buzz_set_duty_cycle(buzz_t *ctx, float duty_cycle)
BUZZ sets PWM duty cycle.
buzz_t::pwm
pwm_t pwm
Definition: buzz.h:186
buzz_init
err_t buzz_init(buzz_t *ctx, buzz_cfg_t *cfg)
BUZZ initialization function.
BUZZ_ERROR
@ BUZZ_ERROR
Definition: buzz.h:217
buzz_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: buzz.h:206
buzz_cfg_t::pwm
pin_name_t pwm
Definition: buzz.h:202