added lines which help to align pins without zebra
[linux-gpio-pinout] / gpio.pl
diff --git a/gpio.pl b/gpio.pl
index 659a998..5b49c16 100755 (executable)
--- a/gpio.pl
+++ b/gpio.pl
@@ -7,15 +7,17 @@ use Getopt::Long;
 
 my $opt_svg = $ENV{SVG} || 0;
 my $opt_alt = $ENV{ALT} || 0;
-my $opt_invert = $ENV{INVERT} = 0;
-my $opt_vertical = $ENV{VERTICAL} = 0;
-my $opt_kernel = $ENV{kernel} = 1;
+my $opt_invert = $ENV{INVERT} || 0;
+my $opt_vertical = $ENV{VERTICAL} || 0;
+my $opt_zebra = $ENV{ZEBRA} || 0;
+my $opt_lines = $ENV{LINES} || 0;
 GetOptions(
        'svg!' => \$opt_svg,
        'alt!' => \$opt_alt,
        'invert!' => \$opt_invert,
        'vertical!' => \$opt_vertical,
-       'kernel!' => \$opt_kernel,
+       'zebra!' => \$opt_zebra,
+       'lines!' => \$opt_lines,
 );
 
 # svg font hints
@@ -76,8 +78,6 @@ while(<$fh>) {
                my ($pin, $function) = ($1,$2);
                $pin_function->{$pin} = "$device $function";
 
-               next unless $opt_kernel;
-
                if ( $pins->{$pin} ) {
                        foreach my $line ( @{$pins->{$pin}} ) {
 warn "XXX $pin $line";
@@ -105,11 +105,15 @@ foreach my $line (@lines) {
                push @line_parts, [ $line ] unless $opt_svg;
                next;
        }
-       $line =~ s/(\[(:?uart|serial))([^\t]*\]\s[^\t]*(rx|tx)d?)/$1 $3$2/gi;
-       $line =~ s/(\[i2c)([^\t]*\]\s[^\t]*(sclk?|sda))/$1 $3$2/gi;
+       $line =~ s/(\[(?:uart|serial))([^\t]*\]\s[^\t]*(rx|tx)d?)/$1 $3$2/gi;
+       $line =~ s/(\[i2c)([^\t]*\]\s[^\t]*(scl?k?|sda))/$1 $3$2/gi;
        $line =~ s/(\[spi)([^\t]*\]\s[^\t]*(miso|mosi|s?clk|c[se]\d*))/$1 $3$2/gi;
        $line =~ s/\s*\([^\)]+\)//g if ! $opt_alt;
 
+       # shorten duplicate kernel device/function
+       $line =~ s/\[serial (\w+) (uart\d+)\]/[$2 $1]/g;
+       $line =~ s/\[(\w+) (\w+) \1(\d+)\]/[$1$3 $2]/g;
+
        my @v = split(/\s*\t+\s*/,$line,4);
        push @line_parts, [ @v ];
        foreach my $i ( 0 .. 3 ) {
@@ -161,7 +165,7 @@ my $cols = {        # foreground background
        vcc  => [ '#ff0000', '#ffff00' ],
        gnd  => [ '#000000', '#00ffff' ],
        i2c  => [ '#008800', '#ffcccc' ],
-       uart => [ '#000088', '#ccffcc' ],
+       serial=>[ '#000088', '#ccffcc' ],
        spi  => [ '#880000', '#ccccff' ],
 };
 
@@ -211,7 +215,7 @@ sub svg_style {
                my ($fg,$bg) = @{ $cols->{gnd} };
                rect $x,$y,$col,$bg;
                return qq{ style="fill:$fg"};
-       } elsif ( $name =~ m/\[(\w+)\d/ ) { # kernel
+       } elsif ( $name =~ m/\[(\w+)/ ) { # kernel
                my $dev = $1;
                my ($fg,$bg) = @{ $cols->{txt} };
                ($fg,$bg) = @{ $cols->{$dev} } if exists $cols->{$dev};
@@ -250,6 +254,12 @@ my $max_x = $x;
 $max_x += $max_len[$_] * $font_w foreach ( 0 .. 3 );
 cut_mark $max_x, $y;
 
+sub line {
+       my ($x,$y,$max_x) = @_;
+       push @cut_marks, sprintf($line_fmt, $x, $y-$font_b, $max_x, $y-$font_b);
+}
+
+
 my $last_cut_mark = 0;
 
 foreach my $i ( 0 .. $#line_parts ) {
@@ -264,6 +274,7 @@ foreach my $i ( 0 .. $#line_parts ) {
                                cut_mark $x, $y;
                                cut_mark $max_x, $y;
                                $last_cut_mark = 1;
+                               line $x, $y, $max_x if $opt_lines;
                                $y += 15; # make spacing between pinouts
                        }
                } elsif ( $last_cut_mark ) {
@@ -275,6 +286,8 @@ foreach my $i ( 0 .. $#line_parts ) {
                        #warn "CUTMARK no magic";
                }
 
+               line $x, $y, $max_x if $opt_lines && exists $line->[1];
+
                my ($fg,$bg) = @{ $cols->{txt} };
                my $tspan = qq{<tspan x="$x" y="$y" style="line-height:2.54;fill:$fg;stroke:none;">\n};
 
@@ -291,8 +304,10 @@ foreach my $i ( 0 .. $#line_parts ) {
                push @later,sprintf $tspan, @$line;
                $y += 2.54;
 
-               # swap pin colors for line stripes
-               swap_cols $_ foreach qw( pins txt );
+               # swap pin colors for line stripe
+               if ( $opt_zebra ) {
+                       swap_cols $_ foreach qw( pins txt );
+               }
 
        } else {