summaryrefslogtreecommitdiffstats
path: root/data/sysrom/kbd/keymap.pl
blob: 69c5887f7aec102f7acbc59f620c03b5107a2044 (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
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
#!/usr/bin/perl

use Encode;

for ($i = 0; $i < 256; $i++) {
    $keytype[$i] = "KEY_IGNORE";
    $keydata[$i] = [];
}

$max_nontriv_key = -1;

while (defined($line = <>)) {
    chomp $line;
    $line =~ s/^(|.*?[^\+])\#.*$/\1/;

    $line = Encode::decode_utf8($line);

    if ($line =~ /^([0-9a-f]+)\s+(\S+)(|\s+(.*))$/i) {
	$key  = hex $1;
	$type = $2;
	$data = $4;

	$keytype[$key] = "KEY_\U$type";

	@datal = split(/\s+/, $data);
	@datan = ();

	foreach $d (@datal) {
	    if ($d =~ /^(0|)x([0-9a-f]{1,2})$/i ) {
		$d = hex $2;
	    } elsif ($d =~ /^\+(.)$/) {
		$d = ord $1;
	    } elsif ($d =~ /^([0-9]+)$/) {
		$d = $1 + 0;
	    } else {
		printf STDERR "Key %02x: unknown string: $d\n", $key;
		$d = 0;
	    }
	    push(@datan, $d);
	}

	$keydata[$key] = [@datan];
	if (scalar(@datan) && $key >= $max_nontriv_key) {
	    $max_nontriv_key = $key;
	}
    }
}

print "#include \"keyboard.h\"\n\n";

print "const uint8_t key_type[256] = {\n";
for ($i = 0; $i < 256; $i++) {
    printf "\t/* 0x%02x */ %s,\n", $i, $keytype[$i];
}
print "};\n\n";

printf "const uint8_t key_data[%d][8] = {\n", $max_nontriv_key+1;
for ($i = 0; $i <= $max_nontriv_key; $i++) {
    printf "\t/* 0x%02x */ ", $i;
    $c = '{';
    @datan = @{$keydata[$i]};
    for ($j = 0; $j < 8; $j++) {
	$d = shift(@datan);
	printf("%s0x%02x", $c, $d);
	$c = ',';
    }
    print "},\n";
}
print "};\n";