buzz2  2.0.0.0
buzz2.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 BUZZ2_H
29 #define BUZZ2_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 BUZZ2_DEF_FREQ 5000
70  // buzz2_cfg
72 
82 #define BUZZ2_NOTE_C2 65
83 #define BUZZ2_NOTE_Db2 69
84 #define BUZZ2_NOTE_D2 73
85 #define BUZZ2_NOTE_Eb2 78
86 #define BUZZ2_NOTE_E2 82
87 #define BUZZ2_NOTE_F2 87
88 #define BUZZ2_NOTE_Gb2 93
89 #define BUZZ2_NOTE_G2 98
90 #define BUZZ2_NOTE_Ab2 104
91 #define BUZZ2_NOTE_A2 110
92 #define BUZZ2_NOTE_Bb2 117
93 #define BUZZ2_NOTE_B2 123
94 #define BUZZ2_NOTE_C3 131
95 #define BUZZ2_NOTE_Db3 139
96 #define BUZZ2_NOTE_D3 147
97 #define BUZZ2_NOTE_Eb3 156
98 #define BUZZ2_NOTE_E3 165
99 #define BUZZ2_NOTE_F3 175
100 #define BUZZ2_NOTE_Gb3 185
101 #define BUZZ2_NOTE_G3 196
102 #define BUZZ2_NOTE_Ab3 208
103 #define BUZZ2_NOTE_A3 220
104 #define BUZZ2_NOTE_AS3 233
105 #define BUZZ2_NOTE_B3 247
106 #define BUZZ2_NOTE_C4 262
107 #define BUZZ2_NOTE_Db4 277
108 #define BUZZ2_NOTE_D4 294
109 #define BUZZ2_NOTE_Eb4 311
110 #define BUZZ2_NOTE_E4 330
111 #define BUZZ2_NOTE_F4 349
112 #define BUZZ2_NOTE_Gb4 370
113 #define BUZZ2_NOTE_G4 392
114 #define BUZZ2_NOTE_Ab4 415
115 #define BUZZ2_NOTE_A4 440
116 #define BUZZ2_NOTE_Bb4 466
117 #define BUZZ2_NOTE_B4 494
118 #define BUZZ2_NOTE_C5 523
119 #define BUZZ2_NOTE_Db5 554
120 #define BUZZ2_NOTE_D5 587
121 #define BUZZ2_NOTE_Eb5 622
122 #define BUZZ2_NOTE_E5 659
123 #define BUZZ2_NOTE_F5 698
124 #define BUZZ2_NOTE_Gb5 740
125 #define BUZZ2_NOTE_G5 784
126 #define BUZZ2_NOTE_Ab5 831
127 #define BUZZ2_NOTE_A5 880
128 #define BUZZ2_NOTE_Bb5 932
129 #define BUZZ2_NOTE_B5 988
130 #define BUZZ2_NOTE_C6 1047
131 #define BUZZ2_NOTE_Db6 1109
132 #define BUZZ2_NOTE_D6 1175
133 #define BUZZ2_NOTE_Eb6 1245
134 #define BUZZ2_NOTE_E6 1319
135 #define BUZZ2_NOTE_F6 1397
136 #define BUZZ2_NOTE_Gb6 1480
137 #define BUZZ2_NOTE_G6 1568
138 #define BUZZ2_NOTE_Ab6 1661
139 #define BUZZ2_NOTE_A6 1760
140 #define BUZZ2_NOTE_Bb6 1865
141 #define BUZZ2_NOTE_B6 1976
142 #define BUZZ2_NOTE_C7 2093
143 #define BUZZ2_NOTE_Db7 2217
144 #define BUZZ2_NOTE_D7 2349
145 #define BUZZ2_NOTE_Eb7 2489
146 #define BUZZ2_NOTE_E7 2637
147 #define BUZZ2_NOTE_F7 2794
148 #define BUZZ2_NOTE_Gb7 2960
149 #define BUZZ2_NOTE_G7 3136
150 #define BUZZ2_NOTE_Ab7 3322
151 #define BUZZ2_NOTE_A7 3520
152 #define BUZZ2_NOTE_Bb7 3729
153 #define BUZZ2_NOTE_B7 3951
154 #define BUZZ2_NOTE_C8 4186
155 #define BUZZ2_NOTE_Db8 4435
156 #define BUZZ2_NOTE_D8 4699
157 #define BUZZ2_NOTE_Eb8 4978
158  // buzz2_freq
159 
174 #define BUZZ2_MAP_MIKROBUS( cfg, mikrobus ) \
175  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
176  // buzz2_map // buzz2
179 
189 typedef struct
190 {
191  // Modules
192 
193  pwm_t pwm;
195  // ctx variable
196 
197  uint32_t pwm_freq;
199 } buzz2_t;
200 
205 typedef struct
206 {
207  // Communication gpio pins
208 
209  pin_name_t pwm;
211  // Static variable
212 
213  uint32_t dev_pwm_freq;
215 } buzz2_cfg_t;
216 
221 typedef enum
222 {
223  BUZZ2_OK = 0,
224  BUZZ2_ERROR = -1
225 
227 
244 
259 err_t buzz2_init ( buzz2_t *ctx, buzz2_cfg_t *cfg );
260 
274 err_t buzz2_set_duty_cycle ( buzz2_t *ctx, float duty_cycle );
275 
286 void buzz2_play_sound ( buzz2_t *ctx, uint16_t freq, uint16_t level, uint16_t duration );
287 
299 err_t buzz2_pwm_stop ( buzz2_t *ctx );
300 
311 err_t buzz2_pwm_start ( buzz2_t *ctx );
312 
313 #ifdef __cplusplus
314 }
315 #endif
316 #endif // BUZZ2_H
317  // buzz2
319 
320 // ------------------------------------------------------------------------ END
buzz2_set_duty_cycle
err_t buzz2_set_duty_cycle(buzz2_t *ctx, float duty_cycle)
BUZZ 2 sets PWM duty cycle.
buzz2_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: buzz2.h:213
BUZZ2_ERROR
@ BUZZ2_ERROR
Definition: buzz2.h:224
buzz2_play_sound
void buzz2_play_sound(buzz2_t *ctx, uint16_t freq, uint16_t level, uint16_t duration)
Play sound function.
buzz2_t::pwm_freq
uint32_t pwm_freq
Definition: buzz2.h:197
buzz2_pwm_stop
err_t buzz2_pwm_stop(buzz2_t *ctx)
BUZZ 2 stop PWM module.
buzz2_t
BUZZ 2 Click driver selector.
Definition: buzz2.h:190
buzz2_init
err_t buzz2_init(buzz2_t *ctx, buzz2_cfg_t *cfg)
BUZZ 2 initialization function.
buzz2_pwm_start
err_t buzz2_pwm_start(buzz2_t *ctx)
BUZZ 2 start PWM module.
BUZZ2_OK
@ BUZZ2_OK
Definition: buzz2.h:223
buzz2_cfg_setup
void buzz2_cfg_setup(buzz2_cfg_t *cfg)
BUZZ 2 configuration object setup function.
buzz2_t::pwm
pwm_t pwm
Definition: buzz2.h:193
buzz2_cfg_t
BUZZ 2 Click configuration object.
Definition: buzz2.h:206
buzz2_cfg_t::pwm
pin_name_t pwm
Definition: buzz2.h:209
buzz2_return_value_t
buzz2_return_value_t
BUZZ 2 Click return value data.
Definition: buzz2.h:222