X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=gpio.pl;h=d9fffeb6e798dfb6ca472e991801a966fdfa0854;hb=306e90392921d984e928ef87a43a3c392019fd46;hp=e26e23ae0c273dad73a8b2ff34b33b66a1fae22f;hpb=b329cd14fa50e4fdeca63aec3802de414d47764d;p=linux-gpio-pinout diff --git a/gpio.pl b/gpio.pl index e26e23a..d9fffeb 100755 --- 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 @@ -47,8 +49,6 @@ while() { } else { $include = 0; } - } elsif ( m/^#\s+/ ) { - $include = 1; } elsif ( $include ) { push @{ $pins->{$1} }, $line_i while ( m/\t(\w+\d+)/g ); @@ -60,6 +60,9 @@ while() { } } +shift(@lines) while ( ! $lines[0] ); # remove empty at beginning +pop(@lines) while ( ! $lines[-1] ); # remove empty at end + die "add pin definition for # $model" unless $pins; warn "# pins ",dump($pins); @@ -76,8 +79,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"; @@ -110,6 +111,10 @@ foreach my $line (@lines) { $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 ) { @@ -250,6 +255,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 +275,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 +287,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{\n}; @@ -291,8 +305,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 { @@ -307,6 +323,10 @@ foreach my $i ( 0 .. $#line_parts ) { } if ( $opt_svg ) { + cut_mark $x,$y; + cut_mark $max_x,$y; + line $x, $y, $max_x if $opt_lines; + print qq{