-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logic_in.c
68 lines (59 loc) · 1.6 KB
/
Logic_in.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
/*!\file Logic_in.c
** \author SMFSW
** \copyright MIT (c) 2017-2024, SMFSW
** \brief Logic input handling
**/
/****************************************************************/
#include "Logic_in.h"
/****************************************************************/
void NONNULLX__(1) Logic_in_init( Logic_in * const in, GPIO_PinState (*getter)(const Logic_in * const),
uint32_t * const addr, const uint32_t pos, const GPIO_PinState polarity, const uint16_t filter,
void (*onSet)(const Logic_in * const), void (*onReset)(const Logic_in * const), const bool repeat)
{
in->cfg.get = getter;
in->cfg.LOGx = addr;
in->cfg.LOG_Pos = pos;
in->cfg.polarity = polarity & 1U; // Ensuring polarity is boolean value
in->cfg.filt = filter;
in->cfg.onSet = onSet;
in->cfg.onReset = onReset;
in->cfg.repeat = repeat;
in->in = false;
in->mem = false;
in->edge = NoEdge;
in->hIn = 0;
}
void NONNULL__ Logic_in_handler(Logic_in * const in)
{
GPIO_PinState val = in->cfg.polarity;
if (in->cfg.get) { val = in->cfg.get(in); }
else if (in->cfg.LOGx) { val = RSHIFT(*((uint32_t *) in->cfg.LOGx), in->cfg.LOG_Pos) & 1U; }
if (val == in->cfg.polarity)
{
if (TPSSUP_MS(in->hIn, in->cfg.filt)) { in->in = true; }
}
else
{
in->in = false;
in->hIn = HALTicks();
}
if (in->in == in->mem)
{
in->edge = NoEdge;
if ((in->in) && (in->cfg.repeat))
{
if (in->cfg.onSet) { in->cfg.onSet(in); }
}
}
else if (in->in > in->mem)
{
in->edge = Rising;
if (in->cfg.onSet) { in->cfg.onSet(in); }
}
else
{
in->edge = Falling;
if (in->cfg.onReset) { in->cfg.onReset(in); }
}
in->mem = in->in;
}