chiark / gitweb /
pcb/points-pin-alloc: Initial checkin
[trains.git] / pcb / points-pin-alloc-gen
1 #!/usr/bin/perl -w
2
3 use strict qw(refs vars);
4
5 use POSIX;
6 use IO::Handle;
7
8 our @boards;
9 foreach (@ARGV) {
10     m/^(\w+)\:(\d+)$/ or die "$_ ?";
11     foreach (my $i=0; $i<$2; $i++) { push @boards, $1; }
12 }
13
14 our @pins;
15 our @pin2otherdesc;
16 while (<DATA>) {
17     m/^(\d+)\t(\S.*\S)\s+/ or die;
18     push @pins, $1;
19     $pin2otherdesc[$1]= $2;
20 }
21
22 our %boardpin2point;
23 foreach my $board (0..$#boards) {
24     my $bkind= $boards[$board];
25     next if exists $boardpin2point{$bkind};
26     open NI, "$bkind.net-info" or die "$bkind $!";
27     while (<NI>) {
28         next if m/^\#/;
29         while (s/\\\n$//) { $_ .= <NI>; }
30         next unless m/\S/;
31         chomp;
32         my ($netname, $type, $pins) = m/^(\w+)\s+(\w+)\s+(\S.*)?$/
33             or die "$_ ?";
34         next unless defined $pins;
35         $pins= " $pins ";
36         $pins =~ m/\sPIC-(\d+)\s/ or next;
37         my $pin= $1;
38         $netname= "__${netname}__";
39         $netname =~ m/__pt(\d+)__/ or next;
40         my $point= $1;
41         die "$netname $pin" unless defined $pin2otherdesc[$pin];
42         $boardpin2point{$bkind}[$pin]= $point;
43     }
44     NI->error and die "$bkind $!";
45     close NI;
46 }
47
48 print <<END;
49 \@SysInclude { tbl }
50 \@SysInclude { doc }
51 \@Doc \@Text \@Begin
52 END
53
54 print "\@Tbl\n";
55
56 my (@formats,@cells);
57 my %formats;
58 my $body='';
59 my $cellix;
60 my $nextformat= 'a';
61
62 sub startrow () {
63     $cellix= "A";
64 }
65
66 sub endrow () {
67     my $format= join ' | ', @formats;
68     my $formatname= $formats{$format};
69     if (!defined $formatname) {
70         $formatname= $nextformat++;
71         $formats{$format}= $formatname;
72         print " ${formatname}format { $format }\n";
73     }
74     $body .= "\@Row${formatname}\n ".join("\n ", @cells)."\n";
75     @formats= @cells= ();
76 }
77
78 sub cell ($$) {
79     my ($fmt, $data) = @_;
80     my $ix= $cellix++; #"C".scalar @cells;
81     push @formats, '@Cell '.$fmt." $ix";
82     push @cells, "$ix { $data }";
83 }
84
85 startrow();
86 cell('', '@B pin');
87 cell('', '@B { alternative uses }');
88 foreach my $board (0..$#boards) {
89     cell('', "$boards[$board]");
90 }
91 endrow();
92
93 foreach my $pin (@pins) {
94     startrow();
95     cell('', $pin);
96     cell('', "\"$pin2otherdesc[$pin]\"");
97     foreach my $board (0..$#boards) {
98         my $point= $boardpin2point{$boards[$board]}[$pin];
99         if (!defined $point) {
100             cell('paint { lightgrey }', '');
101         } else {
102             cell('', "PT$point");
103         }
104     }
105     endrow();
106 }
107 print "{\n",$body,"}\n";
108
109 print <<END;
110 \@End \@Text
111 END
112
113 STDOUT->error and die $!;
114
115 __DATA__
116 40      (useable for point only)
117 39      (useable for point only)
118 38      Interrupt on change
119 37      Interrupt on change
120 36      GPIO
121 35      External Interrupt 2
122 34      External Interrupt 1
123 33      External Interrupt 0
124 30      ECCP1 PWM output D
125 29      ECCP1 PWN output C
126 28      ECCP1 PWN output B
127 27      ECCP1 PWN output A
128 26      RS232 RX
129 25      RS232 TX
130 24      GPIO
131 22      Comparator 2 input
132 2       Analogue in 0 / Comparator ref out
133 3       Analogue in 1
134 15      Timer 1 osc out / Timer 1,3 ext clock in
135 16      Timer 1 osc in