blob: 1cc89be995e672b8b2cb509239713d6e38aa7a4f (
plain)
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
|
component dbounce """alternative debounce component\n
This component is similar to the \\fBdebounce\\fR component\n
(man \\fBdebounce\\fR) but uses settable delay pins for each instance\n
and supports \\fBcount\\fR= or \\fBnames\\fR= parameters\n
(groups are not used)""";
pin in bit in;
pin out bit out;
pin in u32 delay = 5;
variable int state;
function _ nofp;
license "GPL";
author "Dewey Garrett";
;;
FUNCTION(_) {
if (in) {
/* input true, is state at threshold? */
if (state < delay) {
/* no, increment */
state++;
} else {
/* yes, set output */
out = 1;
}
} else {
/* input false, is state at zero? */
if (state > 0) {
/* no, decrement */
state--;
} else {
/* yes, clear output */
out = 0;
}
}
}
|