-
Notifications
You must be signed in to change notification settings - Fork 53
/
cmd-keypad.c
85 lines (74 loc) · 1.32 KB
/
cmd-keypad.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
81
82
83
84
85
#include <string.h>
#include "bionic.h"
#include "memio.h"
#include "printf.h"
#include "serial.h"
#include "fernvale-kbd.h"
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*x))
#endif
const char key_vals[] = "LRUDAB123456789*0#";
const uint32_t key_addr[] = {
KBD_MEM2,
KBD_MEM2,
KBD_MEM1,
KBD_MEM1,
KBD_MEM3,
KBD_MEM3,
KBD_MEM2,
KBD_MEM1,
KBD_MEM3,
KBD_MEM2,
KBD_MEM1,
KBD_MEM3,
KBD_MEM2,
KBD_MEM1,
KBD_MEM3,
KBD_MEM2,
KBD_MEM2,
KBD_MEM2,
};
const uint32_t key_mask[] = {
0x0000fffb,
0x0000fff7,
0x0000fdff,
0x0000fbff,
0x0000ffef,
0x0000ffdf,
0x0000ffef,
0x0000f7ff,
0x0000ffbf,
0x0000ffdf,
0x0000efff,
0x0000ff7f,
0x0000ffbf,
0x0000dfff,
0x0000feff,
0x0000dfff,
0x0000bfff,
0x00007fff,
};
int cmd_keypad(int argc, char **argv)
{
int end = 0;
uint32_t key_state[18] = {0};
printf("Press %c on keypad or any key on serial to exit\n",
key_vals[ARRAY_SIZE(key_vals) - 2]);
while (!end && !serial_available()) {
int key;
for (key = 0; key < (ARRAY_SIZE(key_vals) - 1); key++) {
int v = readl(key_addr[key]);
int newstate = (v == key_mask[key]);
if (newstate && !key_state[key]) {
serial_putc(key_vals[key]);
if (key == (ARRAY_SIZE(key_vals) - 2))
end = 1;
if (argc)
end = 1;
}
key_state[key] = newstate;
}
}
printf("\n");
return 0;
}