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 "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_pwm.h"
48 
69 #define BUZZ_DEF_FREQ 5000
70  // buzz_cfg
72 
82 #define BUZZ_NOTE_C2 65
83 #define BUZZ_NOTE_Db2 69
84 #define BUZZ_NOTE_D2 73
85 #define BUZZ_NOTE_Eb2 78
86 #define BUZZ_NOTE_E2 82
87 #define BUZZ_NOTE_F2 87
88 #define BUZZ_NOTE_Gb2 93
89 #define BUZZ_NOTE_G2 98
90 #define BUZZ_NOTE_Ab2 104
91 #define BUZZ_NOTE_A2 110
92 #define BUZZ_NOTE_Bb2 117
93 #define BUZZ_NOTE_B2 123
94 #define BUZZ_NOTE_C3 131
95 #define BUZZ_NOTE_Db3 139
96 #define BUZZ_NOTE_D3 147
97 #define BUZZ_NOTE_Eb3 156
98 #define BUZZ_NOTE_E3 165
99 #define BUZZ_NOTE_F3 175
100 #define BUZZ_NOTE_Gb3 185
101 #define BUZZ_NOTE_G3 196
102 #define BUZZ_NOTE_Ab3 208
103 #define BUZZ_NOTE_A3 220
104 #define BUZZ_NOTE_AS3 233
105 #define BUZZ_NOTE_B3 247
106 #define BUZZ_NOTE_C4 262
107 #define BUZZ_NOTE_Db4 277
108 #define BUZZ_NOTE_D4 294
109 #define BUZZ_NOTE_Eb4 311
110 #define BUZZ_NOTE_E4 330
111 #define BUZZ_NOTE_F4 349
112 #define BUZZ_NOTE_Gb4 370
113 #define BUZZ_NOTE_G4 392
114 #define BUZZ_NOTE_Ab4 415
115 #define BUZZ_NOTE_A4 440
116 #define BUZZ_NOTE_Bb4 466
117 #define BUZZ_NOTE_B4 494
118 #define BUZZ_NOTE_C5 523
119 #define BUZZ_NOTE_Db5 554
120 #define BUZZ_NOTE_D5 587
121 #define BUZZ_NOTE_Eb5 622
122 #define BUZZ_NOTE_E5 659
123 #define BUZZ_NOTE_F5 698
124 #define BUZZ_NOTE_Gb5 740
125 #define BUZZ_NOTE_G5 784
126 #define BUZZ_NOTE_Ab5 831
127 #define BUZZ_NOTE_A5 880
128 #define BUZZ_NOTE_Bb5 932
129 #define BUZZ_NOTE_B5 988
130 #define BUZZ_NOTE_C6 1047
131 #define BUZZ_NOTE_Db6 1109
132 #define BUZZ_NOTE_D6 1175
133 #define BUZZ_NOTE_Eb6 1245
134 #define BUZZ_NOTE_E6 1319
135 #define BUZZ_NOTE_F6 1397
136 #define BUZZ_NOTE_Gb6 1480
137 #define BUZZ_NOTE_G6 1568
138 #define BUZZ_NOTE_Ab6 1661
139 #define BUZZ_NOTE_A6 1760
140 #define BUZZ_NOTE_Bb6 1865
141 #define BUZZ_NOTE_B6 1976
142 #define BUZZ_NOTE_C7 2093
143 #define BUZZ_NOTE_Db7 2217
144 #define BUZZ_NOTE_D7 2349
145 #define BUZZ_NOTE_Eb7 2489
146 #define BUZZ_NOTE_E7 2637
147 #define BUZZ_NOTE_F7 2794
148 #define BUZZ_NOTE_Gb7 2960
149 #define BUZZ_NOTE_G7 3136
150 #define BUZZ_NOTE_Ab7 3322
151 #define BUZZ_NOTE_A7 3520
152 #define BUZZ_NOTE_Bb7 3729
153 #define BUZZ_NOTE_B7 3951
154 #define BUZZ_NOTE_C8 4186
155 #define BUZZ_NOTE_Db8 4435
156 #define BUZZ_NOTE_D8 4699
157 #define BUZZ_NOTE_Eb8 4978
158  // buzz_freq
160 
177 #define BUZZ_MAP_MIKROBUS( cfg, mikrobus ) \
178  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
179  // buzz_map // buzz
182 
192 typedef struct
193 {
194  // Modules
195 
196  pwm_t pwm;
198  // ctx variable
199 
200  uint32_t pwm_freq;
202 } buzz_t;
203 
208 typedef struct
209 {
210  // Communication gpio pins
211 
212  pin_name_t pwm;
214  // Static variable
215 
216  uint32_t dev_pwm_freq;
218 } buzz_cfg_t;
219 
224 typedef enum
225 {
226  BUZZ_OK = 0,
227  BUZZ_ERROR = -1
228 
230 
247 
262 err_t buzz_init ( buzz_t *ctx, buzz_cfg_t *cfg );
263 
276 err_t buzz_set_duty_cycle ( buzz_t *ctx, float duty_cycle );
277 
289 err_t buzz_pwm_stop ( buzz_t *ctx );
290 
302 err_t buzz_pwm_start ( buzz_t *ctx );
303 
316 void buzz_play_sound ( buzz_t *ctx, uint16_t freq, uint16_t level, uint16_t duration );
317 
318 #ifdef __cplusplus
319 }
320 #endif
321 #endif // BUZZ_H
322  // buzz
324 
325 // ------------------------------------------------------------------------ END
buzz_cfg_t
BUZZ Click configuration object.
Definition: buzz.h:209
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:225
buzz_t
BUZZ Click driver selector.
Definition: buzz.h:193
buzz_t::pwm_freq
uint32_t pwm_freq
Definition: buzz.h:200
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:226
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:196
buzz_init
err_t buzz_init(buzz_t *ctx, buzz_cfg_t *cfg)
BUZZ initialization function.
BUZZ_ERROR
@ BUZZ_ERROR
Definition: buzz.h:227
buzz_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: buzz.h:216
buzz_cfg_t::pwm
pin_name_t pwm
Definition: buzz.h:212