forked from semerad/gt3b
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buzzer.c
81 lines (68 loc) · 1.8 KB
/
buzzer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* @copyright
* Copyright (C) 2011 Pavel Semerad
*
* @file
* $RCSfile: $
*
* @purpose
* gt3b alternative firmware - buzzer routines
*
* @cfg_management
* $Source: $
* $Author: $
* $Date: $
*
* @comment
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "buzzer.h"
#include "config.h"
/** @brief
* buzzer initialization
*/
void buzzer_init(void) {
IO_OP(D, 4); // buzzer pin
BUZZER0; // stop buzzer
}
// buzzer counters and flags
_Bool buzzer_running; // 1 when running
u8 buzzer_cnt_on; // time to be ON
u8 buzzer_cnt_off; // time to be OFF
u16 buzzer_count; // length of beeping
u8 buzzer_cnt; // helper counter
// more beeps: on time, off time and count of beeps
void buzzer_on(u8 on_5ms, u8 off_5ms, u16 count) {
buzzer_cnt_on = buzzer_cnt = on_5ms;
buzzer_cnt_off = off_5ms;
buzzer_count = count;
BUZZER1;
buzzer_running = 1;
}
/// @brief
/// stop buzzer
///
void buzzer_off(void) {
BUZZER0;
buzzer_running = 0;
}
// one beep
void beep(u8 len_5ms) {
if (buzzer_running) return;
buzzer_on(len_5ms, 0, 1);
}
// key beep if enabled in config
void key_beep(void) {
if (cg.key_beep) beep(1);
}