better fit pin descriptions, make rpi gpio optional
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 5 Jul 2016 19:58:35 +0000 (21:58 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 5 Jul 2016 19:58:35 +0000 (21:58 +0200)
openocd-jtag-boundary-scan.pl

index bd7518b..4e3632c 100755 (executable)
@@ -32,7 +32,9 @@ my $parse_regex = join('|', qw(
 
 $|=1; # flush stdout
 
-require 'gpio.pl';
+my $have_gpio = `which gpio`;
+warn "# ", ! $have_gpio ? "DOESN'T " : '', "have rpi gpio\n";
+require 'gpio.pl' if $have_gpio;
 
 open(my $bsdl, '<', $bsdl_file);
 while(<$bsdl>) {
@@ -114,7 +116,7 @@ foreach my $pin_file ( glob "pins/$entity*.tsv" ) {
                chomp;
                my ($pin,$desc, $bcm) = split(/\t+/,$_,3);
                $pin_desc->{$pin} = $desc;
-               gpio::add_bcm_desc( $bcm => $desc );
+               gpio::add_bcm_desc( $bcm => $desc ) if $have_gpio;
        }
        close($fh);
        warn "# $pin_file ",dump($pin_desc);
@@ -184,9 +186,12 @@ sub print_io {
                                        }
                                }
 
-                               printf "%-3d %-3d %-5s %3s %-8s | ", $pin, $o, $io, $bits, $desc;
+                               $desc = ' ' . $desc if length($desc) < 10;
+                               $desc = substr($desc,0,10);
+
+                               printf "%-3d %-3d %-5s %3s%-10s| ", $pin, $o, $io, $bits, $desc;
                        } else {
-                               printf "%-3d ... %-18s | ", $pin, $io, '', '';
+                               printf "%-3d ... %-18s | ", $pin, $io;
                        }
                }
                print "\n";
@@ -237,7 +242,7 @@ while (<$sock>) {
                diff_bits($BSR, $bin);
                $BSR = $bin;
                print_io $bin if $bin ne $last_bits;
-               gpio::pins();
+               gpio::pins() if $have_gpio;
                last;
        } else {
                warn "# in ",dump($_);
@@ -262,7 +267,7 @@ sub diff_bits {
        print "# diff_bits $diff\n";
 }
 
-print "[press enter]\n";
+print "";
 my $cmd = <STDIN>;
 chomp $cmd;
 if ( $cmd =~ /(p|o)(\d+)=(\d+)/ ) {
@@ -311,7 +316,7 @@ warn "XXX",length($old_bsr), " == ",length($b);
        print $sock "irscan $tap $opcode->{SAMPLE}\n"; # SAMPLE/PRELOAD
        print $sock "drscan $tap $BOUNDARY_LENGTH 0\n";
 } else {
-       gpio::cmd( $cmd );
+       gpio::cmd( $cmd ) if $have_gpio;
        print $sock "irscan $tap $opcode->{SAMPLE}\n"; # SAMPLE/PRELOAD
        print $sock "drscan $tap $BOUNDARY_LENGTH 0\n";
 }