display custom pin usage
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 18 Jun 2016 08:53:54 +0000 (10:53 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 18 Jun 2016 08:53:54 +0000 (10:53 +0200)
gpio.pl
pins/bcm-openocd-jtag.tsv [new file with mode: 0644]

diff --git a/gpio.pl b/gpio.pl
index f72f61d..e1d8215 100755 (executable)
--- a/gpio.pl
+++ b/gpio.pl
@@ -1,6 +1,7 @@
 #!/usr/bin/perl
 use warnings;
 use strict;
+use autodie;
 
 package gpio;
 
@@ -9,6 +10,18 @@ use Data::Dump qw(dump);
 my @last;
 my $mode;
 
+my $bcm_desc;
+foreach my $pin_file ( glob 'pins/bcm-*.tsv' ) {
+       open(my $fh, '<', $pin_file);
+       while(<$fh>) {
+               chomp;
+               my ($pin,$desc) = split(/\t+/,$_,2);
+               $bcm_desc->{$pin} = $desc;
+       }
+       close($fh);
+       warn "# $pin_file ",dump($bcm_desc);
+}
+
 sub pins {
 
 my @pcf = `gpio -x pcf8591:120:0x48 readall`;
@@ -33,14 +46,17 @@ foreach (@gpio) {
        my @l = split(/\|/, $line);
        my @o = split(/\|/, $last[$i] || '');
        $last[$i] = $line;
-       $i++;
 
        if ( $#l >= 9 ) {
                no warnings;
+
+               $l[2] = sprintf "%-" . length($l[2]) . 's', ($bcm_desc->{ $1 }||$l[2]) if $l[1] =~ m/(\d+)/;
+               $l[8] = sprintf "%"  . length($l[8]) . 's', ($bcm_desc->{ $1 }||$l[8]) if $l[9] =~ m/(\d+)/;
+
                $mode->{ $l[1]  } = [ $l[4] + 0, $l[2], $l[3] ];
                $mode->{ $l[9]  } = [ $l[6] + 0, $l[8], $l[7] ];
                $mode->{ $l[11] } = [ $l[12], $l[13] ] if $l[13];
-               #warn "## l = ",dump(@l);
+               #warn "## l = ",dump(@l) if $i > 2 && $i < 5;
        }
        
 
@@ -48,11 +64,12 @@ foreach (@gpio) {
                foreach my $i ( 0 .. $#l ) {
                        $l[$i] = "\e[33;7;1m$l[$i]\e[0m" if $l[$i] ne $o[$i];
                }
-               $line = join('|', @l) . "|";
        }
 
+       $line = join('|', @l) . "|";
        print "$line\n";
 
+       $i++;
 }
 
 #warn "# mode = ", dump($mode);
diff --git a/pins/bcm-openocd-jtag.tsv b/pins/bcm-openocd-jtag.tsv
new file mode 100644 (file)
index 0000000..9d5c786
--- /dev/null
@@ -0,0 +1,4 @@
+17     tck
+27     tms
+22     tdi
+18     tdo