mirror of
git://projects.qi-hardware.com/iris.git
synced 2025-04-21 12:27:27 +03:00
working keyboard
This commit is contained in:
@@ -14,7 +14,7 @@ GPIO control:
|
||||
|
||||
// GP ... Registers: one set for each port of 32 pins; total 128 pins means 4 groups. Total size: 4 * 0x30 == 0xc0.
|
||||
#define GPIO_GPDR(n) (GPIO_BASE + (0x00 + (n)*0x30)) // D: data
|
||||
#define GPIO_GPDIR(n) (GPIO_BASE + (0x04 + (n)*0x30)) // DI: data in: 1 is input; 0 is output. Disable interrupts on the pin before touching this.
|
||||
#define GPIO_GPDIR(n) (GPIO_BASE + (0x04 + (n)*0x30)) // DI: data in: 0 is input; 1 is output. Disable interrupts on the pin before touching this.
|
||||
#define GPIO_GPODR(n) (GPIO_BASE + (0x08 + (n)*0x30)) // OD:
|
||||
#define GPIO_GPPUR(n) (GPIO_BASE + (0x0c + (n)*0x30)) // PU: pull-up (1 is enable)
|
||||
#define GPIO_GPALR(n) (GPIO_BASE + (0x10 + (n)*0x30)) // AL: alternate lower: per 2 bit; 00 means use as gpio; other values mean use as alternate function
|
||||
@@ -180,3 +180,134 @@ do { \
|
||||
REG_GPIO_GPALR(0) &= 0xFF000000; \
|
||||
REG_GPIO_GPALR(0) |= 0x00555555; \
|
||||
} while (0)
|
||||
|
||||
|
||||
// Pins on the trendtac:
|
||||
0 keyboard
|
||||
1 keyboard
|
||||
2 keyboard
|
||||
3 keyboard
|
||||
4 keyboard
|
||||
5 keyboard
|
||||
6 keyboard
|
||||
7 keyboard
|
||||
8 keyboard interrupt
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13 touchpad right button
|
||||
14
|
||||
15
|
||||
16 touchpad left button
|
||||
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
|
||||
86
|
||||
87
|
||||
88
|
||||
89
|
||||
90
|
||||
91
|
||||
92
|
||||
93
|
||||
94
|
||||
95
|
||||
96 keyboard
|
||||
97 keyboard
|
||||
98 keyboard
|
||||
99 keyboard
|
||||
100 keyboard
|
||||
101 keyboard
|
||||
102 keyboard
|
||||
103 keyboard
|
||||
104 keyboard
|
||||
105 keyboard
|
||||
106 keyboard
|
||||
107 keyboard
|
||||
108 keyboard
|
||||
109 keyboard
|
||||
110 keyboard
|
||||
111 keyboard
|
||||
112
|
||||
113
|
||||
114
|
||||
115
|
||||
116
|
||||
117
|
||||
118
|
||||
119
|
||||
120
|
||||
121
|
||||
122
|
||||
123
|
||||
124
|
||||
125 keyboard
|
||||
126
|
||||
127
|
||||
|
||||
@@ -16,10 +16,15 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
.globl __start
|
||||
.globl __my_receiver
|
||||
.globl __my_thread
|
||||
.globl __my_memory
|
||||
.globl __my_call
|
||||
.set noreorder
|
||||
|
||||
__start:
|
||||
bal 1f
|
||||
nop
|
||||
.word _gp
|
||||
1:
|
||||
lw $gp, 0($ra)
|
||||
|
||||
@@ -18,63 +18,101 @@
|
||||
|
||||
#include "iris.h"
|
||||
|
||||
// GPIO pins for the keyboard: Rows =
|
||||
// GPIO pins for the keyboard://
|
||||
// Rows = 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 125
|
||||
// Cols = 0, 1, 2, 3, 4, 5, 6, 7
|
||||
|
||||
// Rows: 60...6f; 7d
|
||||
|
||||
// Nicely aligned to a port: use cols as output; rows as input.
|
||||
// Nicely aligned to a port: use rows as output; cols as input.
|
||||
|
||||
// Map memory from b0010000, which is really 10010000 in kseg1.
|
||||
|
||||
#define D(n) (*(volatile unsigned *)(0x00 + 0x30 * n + address))
|
||||
#define DI(n) (*(volatile unsigned *)(0x04 + 0x30 * n + address))
|
||||
#define AL(n) (*(volatile unsigned *)(0x10 + 0x30 * n + address))
|
||||
#define AU(n) (*(volatile unsigned *)(0x14 + 0x30 * n + address))
|
||||
#define D(n) (*(volatile unsigned *)(0x00 + 0x30 * n + address))
|
||||
#define DI(n) (*(volatile unsigned *)(0x04 + 0x30 * n + address))
|
||||
#define PU(n) (*(volatile unsigned *)(0x0c + 0x30 * n + address))
|
||||
#define AL(n) (*(volatile unsigned *)(0x10 + 0x30 * n + address))
|
||||
#define AU(n) (*(volatile unsigned *)(0x14 + 0x30 * n + address))
|
||||
#define IE(n) (*(volatile unsigned *)(0x20 + 0x30 * n + address))
|
||||
|
||||
void event (bool release, unsigned col, unsigned row):
|
||||
debug_set_led ((col & 1) | (row & 2) | (release ? 4 : 0))
|
||||
unsigned const address = 0x00010000
|
||||
|
||||
static void event (bool release, unsigned row, unsigned col):
|
||||
debug_set_led (col * 2 + (release ? 1 : 0))
|
||||
|
||||
static void delay ():
|
||||
for unsigned i = 0; i < 100000; ++i:
|
||||
IE (3) &= ~0x2000ffff
|
||||
|
||||
int main ():
|
||||
// map memory
|
||||
Capability page = memory_create_page (__my_memory)
|
||||
alloc_physical (page, 0x10010000, 0)
|
||||
unsigned const address = 0x00010000
|
||||
memory_map (__my_memory, page, address)
|
||||
memory_map (__my_memory, page, address, 1)
|
||||
|
||||
#if 0
|
||||
// Keyboard stuff doesn't seem to work. Try the simpler part: touchpad buttons.
|
||||
IE (0) &= ~0x00012000
|
||||
AL (0) &= ~0x0c000000
|
||||
AU (0) &= ~0x00000003
|
||||
DI (0) &= ~0x00012000
|
||||
PU (0) &= ~0x00012000
|
||||
|
||||
unsigned old = 0
|
||||
while true:
|
||||
unsigned data = D (0) & 0x00012000
|
||||
if data == old:
|
||||
continue
|
||||
if data & ~old & 0x00010000:
|
||||
event (true, 0, 0)
|
||||
else if ~data & old & 0x00010000:
|
||||
event (false, 0, 0)
|
||||
if data & ~old & 0x00002000:
|
||||
event (true, 1, 1)
|
||||
else if ~data & old & 0x00002000:
|
||||
event (false, 1, 1)
|
||||
old = data
|
||||
#else
|
||||
// Disable all interrupts.
|
||||
IE (3) &= ~0x2000ffff
|
||||
IE (0) &= ~0x000000ff
|
||||
IE (0) &= ~0x000001ff
|
||||
|
||||
// Set all to GPIO
|
||||
// Set all to GPIO.
|
||||
AL (3) = 0
|
||||
AU (3) &= ~0x0c000000
|
||||
AL (0) &= ~0x0000ffff
|
||||
AL (0) &= ~0x0003ffff
|
||||
|
||||
// Set all to input
|
||||
// Set all rows to input and enable the pull-ups.
|
||||
DI (0) &= ~0x000000ff
|
||||
PU (0) |= 0x000000ff
|
||||
|
||||
// Set all columns to output, 0.
|
||||
DI (3) |= 0x2000ffff
|
||||
DI (0) |= 0x000000ff
|
||||
D (3) &= ~0x2000ffff
|
||||
|
||||
unsigned keys[2][8]
|
||||
for unsigned i = 0; i < 8; ++i:
|
||||
keys[1][i] = 0x2000ffff
|
||||
#define NUM_COLS 17
|
||||
unsigned keys[NUM_COLS]
|
||||
for unsigned i = 0; i < NUM_COLS; ++i:
|
||||
keys[i] = 0
|
||||
|
||||
// Pin numbers for the cols, relative to the start of the port (so minus 0x60).
|
||||
int const cols[NUM_COLS] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 29 }
|
||||
while true:
|
||||
// read keyboard
|
||||
for unsigned col = 0; col < 8; ++col:
|
||||
// set col to output, all others to input
|
||||
DI (0) = (DI (0) & ~0x000000ff) | (1 << col)
|
||||
// read input
|
||||
keys[0][col] = D (3) & ~0x2000ffff
|
||||
// Generate events
|
||||
if keys[0][col] == keys[1][col]:
|
||||
continue
|
||||
unsigned bit, b
|
||||
for bit = 1, b = 0; bit < 0x10000; bit <<= 1, ++b:
|
||||
if (keys[0][col] ^ keys[1][col]) & bit:
|
||||
event (keys[0][col] & bit, col, b)
|
||||
if (keys[0][col] ^ keys[1][col]) & 0x20000000:
|
||||
// Not really bit 16, but it's easier to handle.
|
||||
event (keys[0][col] & 0x20000000, col, 16)
|
||||
unsigned data[NUM_COLS]
|
||||
for unsigned col = 0; col < NUM_COLS; ++col:
|
||||
D (3) &= ~0x2000ffff
|
||||
delay ()
|
||||
unsigned zero = ~D (0) & 0x000000ff
|
||||
D (3) = (D (3) & ~0x2000ffff) | (1 << cols[col])
|
||||
delay ()
|
||||
data[col] = D (0) & zero
|
||||
|
||||
// Generate events.
|
||||
for unsigned col = 0; col < NUM_COLS; ++col:
|
||||
for unsigned row = 0; row < 8; ++row:
|
||||
if (data[col] ^ keys[col]) & (1 << row):
|
||||
event (data[col] & (1 << row), row, col)
|
||||
keys[col] = data[col]
|
||||
schedule ()
|
||||
#endif
|
||||
|
||||
@@ -20,4 +20,4 @@
|
||||
|
||||
int main ():
|
||||
while true:
|
||||
__asm__ volatile ("move $v0, $zero; li $a0, 1 ; move $a1, $zero ; move $a2, $a0 ; syscall")
|
||||
schedule ()
|
||||
|
||||
Reference in New Issue
Block a user