gencon.pl 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #!/usr/bin/perl
  2. #
  3. # gencon.pl - Generate generic connectors
  4. #
  5. # Copyright 2012, 2016 by Werner Almesberger
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. sub intro
  13. {
  14. local ($name, $h, $s) = @_;
  15. my $b = $s ? $h + 150 : $h;
  16. $name .= "_S$s" if $s;
  17. print "#\n# $name\n#\n";
  18. print "DEF $name CON 0 40 Y N 1 F N\n";
  19. print "F0 \"CON\" 0 " . ($h + 50) . " 60 H V C CNN\n";
  20. print "F1 \"$name\" 0 " . (-$b - 50) . " 60 H V C CNN\n";
  21. }
  22. sub box
  23. {
  24. local ($h, $s) = @_;
  25. my $b = $s ? $h + 150 : $h;
  26. print "S -100 -$b 100 $h 0 1 0 N\n";
  27. for (my $i = 0; $i != $s; $i++) {
  28. my $n = sprintf("S%d", $i+1);
  29. print "X $n $n " . (400 * ($i - 0.5) * 2) . " " .
  30. (-$h - 100) . " 300 " .
  31. ("R", "L")[$i] . " 50 50 1 1 P\n";
  32. }
  33. }
  34. # Single and dual row, with the same number of pins in each row
  35. sub even
  36. {
  37. local ($x, $s) = @_;
  38. for (my $y = 1; $y <= 2; $y++) {
  39. my $name = "CONN_$x";
  40. my $h = $x / 2 * 100;
  41. $name .= "X$y" if $y > 1;
  42. &intro($name, $h, $s);
  43. print "DRAW\n";
  44. &box($h, $s);
  45. my $n = 1;
  46. for (my $px = 1; $px <= $x; $px++) {
  47. for (my $py = 1; $py <= $y; $py++) {
  48. print "X $n $n " . (400 * ($py - 1.5) * 2) .
  49. " " . ($h - $px * 100 + 50) . " 300 " .
  50. ("?", "R", "L")[$py] . " 50 50 1 1 P\n";
  51. $n++;
  52. }
  53. }
  54. print "ENDDRAW\n";
  55. print "ENDDEF\n";
  56. }
  57. }
  58. # Dual row, with rows differing by one pin (D-Sub and similar)
  59. sub odd
  60. {
  61. local ($x, $s) = @_;
  62. my $h = $x / 2 * 100;
  63. &intro("CONN_$x" . "_" . ($x - 1), $h, $s);
  64. print "DRAW\n";
  65. &box($h, $s);
  66. for (my $px = 1; $px <= $x; $px++) {
  67. print "X $px $px -400 " .
  68. ($h - $px * 100 + 50) . " 300 R 50 50 1 1 P\n";
  69. next if $px == $x;
  70. $n = $px + $x;
  71. print "X $n $n 400 " .
  72. ($h - $px * 100) . " 300 L 50 50 1 1 P\n";
  73. }
  74. print "ENDDRAW\n";
  75. print "ENDDEF\n";
  76. }
  77. print "EESchema-LIBRARY Version 2.3 Date: `date`\n";
  78. print "#encoding utf-8\n";
  79. for ($x = 1; $x <= 40; $x++) {
  80. for ($s = 0; $s <= 2; $s++) {
  81. &even($x, $s);
  82. &odd($x, $s) if $x > 1;
  83. }
  84. }
  85. print "#\n#End Library\n";