buzz  2.0.0.0
buzz.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 BUZZ_H
36 #define BUZZ_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_pwm.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
47 #define BUZZ_NOTE_C2 65
48 #define BUZZ_NOTE_Db2 69
49 #define BUZZ_NOTE_D2 73
50 #define BUZZ_NOTE_Eb2 78
51 #define BUZZ_NOTE_E2 82
52 #define BUZZ_NOTE_F2 87
53 #define BUZZ_NOTE_Gb2 93
54 #define BUZZ_NOTE_G2 98
55 #define BUZZ_NOTE_Ab2 104
56 #define BUZZ_NOTE_A2 110
57 #define BUZZ_NOTE_Bb2 117
58 #define BUZZ_NOTE_B2 123
59 #define BUZZ_NOTE_C3 131
60 #define BUZZ_NOTE_Db3 139
61 #define BUZZ_NOTE_D3 147
62 #define BUZZ_NOTE_Eb3 156
63 #define BUZZ_NOTE_E3 165
64 #define BUZZ_NOTE_F3 175
65 #define BUZZ_NOTE_Gb3 185
66 #define BUZZ_NOTE_G3 196
67 #define BUZZ_NOTE_Ab3 208
68 #define BUZZ_NOTE_A3 220
69 #define BUZZ_NOTE_AS3 233
70 #define BUZZ_NOTE_B3 247
71 #define BUZZ_NOTE_C4 262
72 #define BUZZ_NOTE_Db4 277
73 #define BUZZ_NOTE_D4 294
74 #define BUZZ_NOTE_Eb4 311
75 #define BUZZ_NOTE_E4 330
76 #define BUZZ_NOTE_F4 349
77 #define BUZZ_NOTE_Gb4 370
78 #define BUZZ_NOTE_G4 392
79 #define BUZZ_NOTE_Ab4 415
80 #define BUZZ_NOTE_A4 440
81 #define BUZZ_NOTE_Bb4 466
82 #define BUZZ_NOTE_B4 494
83 #define BUZZ_NOTE_C5 523
84 #define BUZZ_NOTE_Db5 554
85 #define BUZZ_NOTE_D5 587
86 #define BUZZ_NOTE_Eb5 622
87 #define BUZZ_NOTE_E5 659
88 #define BUZZ_NOTE_F5 698
89 #define BUZZ_NOTE_Gb5 740
90 #define BUZZ_NOTE_G5 784
91 #define BUZZ_NOTE_Ab5 831
92 #define BUZZ_NOTE_A5 880
93 #define BUZZ_NOTE_Bb5 932
94 #define BUZZ_NOTE_B5 988
95 #define BUZZ_NOTE_C6 1047
96 #define BUZZ_NOTE_Db6 1109
97 #define BUZZ_NOTE_D6 1175
98 #define BUZZ_NOTE_Eb6 1245
99 #define BUZZ_NOTE_E6 1319
100 #define BUZZ_NOTE_F6 1397
101 #define BUZZ_NOTE_Gb6 1480
102 #define BUZZ_NOTE_G6 1568
103 #define BUZZ_NOTE_Ab6 1661
104 #define BUZZ_NOTE_A6 1760
105 #define BUZZ_NOTE_Bb6 1865
106 #define BUZZ_NOTE_B6 1976
107 #define BUZZ_NOTE_C7 2093
108 #define BUZZ_NOTE_Db7 2217
109 #define BUZZ_NOTE_D7 2349
110 #define BUZZ_NOTE_Eb7 2489
111 #define BUZZ_NOTE_E7 2637
112 #define BUZZ_NOTE_F7 2794
113 #define BUZZ_NOTE_Gb7 2960
114 #define BUZZ_NOTE_G7 3136
115 #define BUZZ_NOTE_Ab7 3322
116 #define BUZZ_NOTE_A7 3520
117 #define BUZZ_NOTE_Bb7 3729
118 #define BUZZ_NOTE_B7 3951
119 #define BUZZ_NOTE_C8 4186
120 #define BUZZ_NOTE_Db8 4435
121 #define BUZZ_NOTE_D8 4699
122 #define BUZZ_NOTE_Eb8 4978
123 
129 #define BUZZ_MAP_MIKROBUS( cfg, mikrobus ) \
130  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
131 
137 #define BUZZ_RETVAL uint8_t
138 
139 #define BUZZ_OK 0x00
140 #define BUZZ_INIT_ERROR 0xFF
141  // End group macro
144 // --------------------------------------------------------------- PUBLIC TYPES
153 typedef struct
154 {
155 
156  // Modules
157 
158  pwm_t pwm;
159 
160  // ctx variable
161 
162  uint32_t pwm_freq;
163 
164 } buzz_t;
165 
169 typedef struct
170 {
171  // Communication gpio pins
172 
173  pin_name_t pwm;
174 
175  // static variable
176 
177  uint32_t dev_pwm_freq;
178 
179 } buzz_cfg_t;
180  // End types group
182 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
183 
189 #ifdef __cplusplus
190 extern "C"{
191 #endif
192 
201 void buzz_cfg_setup ( buzz_cfg_t *cfg );
202 
210 BUZZ_RETVAL buzz_init ( buzz_t *ctx, buzz_cfg_t *cfg );
211 
222 void buzz_play_sound ( buzz_t *ctx, uint16_t freq, uint16_t level, uint16_t duration );
223 
233 void buzz_set_duty_cycle ( buzz_t *ctx, float duty_cycle );
234 
242 void buzz_pwm_stop ( buzz_t *ctx );
243 
251 void buzz_pwm_start ( buzz_t *ctx );
252 
253 #ifdef __cplusplus
254 }
255 #endif
256 #endif // _BUZZ_H_
257  // End public_function group
260 
261 // ------------------------------------------------------------------------- END
buzz_cfg_t
Click configuration structure definition.
Definition: buzz.h:169
buzz_set_duty_cycle
void buzz_set_duty_cycle(buzz_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
buzz_t
Click ctx object definition.
Definition: buzz.h:153
buzz_t::pwm_freq
uint32_t pwm_freq
Definition: buzz.h:162
buzz_init
BUZZ_RETVAL buzz_init(buzz_t *ctx, buzz_cfg_t *cfg)
Initialization function.
BUZZ_RETVAL
#define BUZZ_RETVAL
Definition: buzz.h:137
buzz_cfg_setup
void buzz_cfg_setup(buzz_cfg_t *cfg)
Config Object Initialization function.
buzz_play_sound
void buzz_play_sound(buzz_t *ctx, uint16_t freq, uint16_t level, uint16_t duration)
Play sound function.
buzz_pwm_stop
void buzz_pwm_stop(buzz_t *ctx)
Stop PWM module.
buzz_t::pwm
pwm_t pwm
Definition: buzz.h:158
buzz_pwm_start
void buzz_pwm_start(buzz_t *ctx)
Start PWM module.
buzz_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: buzz.h:177
buzz_cfg_t::pwm
pin_name_t pwm
Definition: buzz.h:173