-
Notifications
You must be signed in to change notification settings - Fork 0
/
digital.cpp
73 lines (69 loc) · 2.4 KB
/
digital.cpp
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
#include "ch.h"
#include "hal.h"
#include "digital.h"
#include "Can.h"
uint8_t digitalInputs[(8 + 7) / 8] = {0}; // Definition and initialization
static THD_WORKING_AREA(waDigitalThread, 128);
static THD_FUNCTION(DigitalThread, p)
{
(void)p;
chRegSetThreadName("Digital_Thread");
while (true)
{
chMtxLock(&digitalInputsMutex);
for (uint8_t i = 0; i < 8; i++)
{
switch (i)
{
case 0:
if(palReadPad(GPIOB, 3)) USTAW_BIT(digitalInputs, i);
else CZYSC_BIT(digitalInputs, i);
break;
case 1:
if(palReadPad(GPIOB, 4)) USTAW_BIT(digitalInputs, i);
else CZYSC_BIT(digitalInputs, i);
break;
case 2:
if(palReadPad(GPIOB, 5)) USTAW_BIT(digitalInputs, i);
else CZYSC_BIT(digitalInputs, i);
break;
case 3:
if(palReadPad(GPIOB, 6)) USTAW_BIT(digitalInputs, i);
else CZYSC_BIT(digitalInputs, i);
break;
case 4:
if(palReadPad(GPIOB, 7)) USTAW_BIT(digitalInputs, i);
else CZYSC_BIT(digitalInputs, i);
break;
case 5:
if(palReadPad(GPIOB, 15)) USTAW_BIT(digitalInputs, i);
else CZYSC_BIT(digitalInputs, i);
break;
case 6:
if(palReadPad(GPIOA, 15)) USTAW_BIT(digitalInputs, i);
else CZYSC_BIT(digitalInputs, i);
break;
case 7:
if(palReadPad(GPIOA, 8)) USTAW_BIT(digitalInputs, i);
else CZYSC_BIT(digitalInputs, i);
break;
default:
break;
}
}
chMtxUnlock(&digitalInputsMutex);
chThdSleepMilliseconds(250);
}
}
void startDigitalThread(void)
{
palSetPadMode(GPIOB, 3, PAL_MODE_INPUT_PULLUP);
palSetPadMode(GPIOB, 4, PAL_MODE_INPUT_PULLUP);
palSetPadMode(GPIOB, 5, PAL_MODE_INPUT_PULLUP);
palSetPadMode(GPIOB, 6, PAL_MODE_INPUT_PULLUP);
palSetPadMode(GPIOB, 7, PAL_MODE_INPUT_PULLUP);
palSetPadMode(GPIOB, 15, PAL_MODE_INPUT_PULLUP);
palSetPadMode(GPIOA, 15, PAL_MODE_INPUT_PULLUP);
palSetPadMode(GPIOA, 8, PAL_MODE_INPUT_PULLUP);
chThdCreateStatic(waDigitalThread, sizeof(waDigitalThread), NORMALPRIO + 2, DigitalThread, NULL);
}