{ ---------------------------------------------------------------------------- ]

  Zdrojový text knihovny pouzder řady TSSOP
  =========================================

  PH 2007


  
  Knihovna vytvořena dle normy JEDEC MO-153 Plastic Thin Shrink Small Outline
  Package z ledna 2005 (vydání F).

  Čísla vrstev upravena pro program Layout verze 4.40.  Knihovnu lze vygenerovat
  příkazem

  genlib -o tssop.pcb tssop.pas

  Po otevření vygenerované knihovny v programu Layout je třeba se přesvědčit,
  zda je nastaven Dimensions | Basic Grid = 0.025 mm, pak knihovnu zapsat zpět.

  Logické typy pájecích bodů nutno upravit dle uživatelových tabulek rozměrů
  (viz komentář níže).

[ ---------------------------------------------------------------------------- }


{ všeobecně využitelné funkce }

function Min (a, b: integer) : integer;
begin
  if a < b then Result := a else Result := b;
end;

function Max (a, b: integer) : integer;
begin
  if a > b then Result := a else Result := b;
end;

function Avg (a, b: integer) : integer;
begin
  Result := (a + b) div 2;
end;

function GetPoint (x, y: integer) : Point;
begin
  Result.x := x;
  Result.y := y;
end;

function GetRect (x1, y1, x2, y2: integer) : Rect;
begin
  Result.Left   := x1;
  Result.Bottom := y1;
  Result.Right  := x2;
  Result.Top    := y2;
end;

function GetRect0 (w, h: integer) : Rect;
begin
  Result.Left   := -w;
  Result.Bottom := -h;
  Result.Right  :=  w;
  Result.Top    :=  h;
end;

function RectCenter (r: Rect) : Point;
begin
  Result.x := Avg (r.Left, r.Right);
  Result.y := Avg (r.Top,  r.Bottom);
end;

function StretchRect (r: Rect; dx, dy: integer) : Rect;
begin
  Result.Left   := r.Left   - dx;
  Result.Bottom := r.Bottom - dy;
  Result.Right  := r.Right  + dx;
  Result.Top    := r.Top    + dy;
end;

{ ---------------------------------------------------------------------------- }

{ procedury pro vykreslení základních tvarů }

{ Procedura DrawPin konvertuje logické typy pájecích bodů na jejich čísla 
  v souboru typu *.pcb formátu užívaného verzí 4.40.  (Složitost kombinování 
  čísla typu a rotace je důsledkem kompatibility s formátem verzí 4.2 a 4.30.) }

procedure DrawPin (PinNumber: integer; x, y: integer; PadType: integer; Rotation: integer);
begin
  if Rotation = 90 then
    PadType := PadType + 256;
  if      (PadType >= 128) and (PadType < 256) then
    PadType := PadType + 128
  else if (PadType >= 256) and (PadType < 384) then
    PadType := PadType - 128;
  if      (PadType >=  64) and (PadType < 128) then
    PadType := PadType + 64
  else if (PadType >= 128) and (PadType < 192) then
    PadType := PadType - 64;
  Pin (PinNumber, x, y, PadType);
end;

procedure DrawRect (r: Rect; LineType, Layer: integer);
begin
  Line (r.Left,  r.Top,
        r.Right, r.Top, LineType, Layer);
  Line (r.Right, r.Bottom);
  Line (r.Left,  r.Bottom);
  Line (r.Left,  r.Top);
end;

procedure DrawSquare (Center: Point; Size: integer; LineType, Layer: integer);
  var r: Rect;
begin
  r := GetRect (Center.x - Size div 2, Center.y - Size div 2,
                Center.x + Size div 2, Center.y + Size div 2);
  DrawRect (r, LineType, Layer);
end;

procedure DrawCircle (Center: Point; Size: integer; LineType, Layer: integer);
begin
  Arc (0, Center.x, Center.y, Size div 2, LineType, Layer);
  Arc (1, Center.x, Center.y, Size div 2);
  Arc (2, Center.x, Center.y, Size div 2);
  Arc (3, Center.x, Center.y, Size div 2);
end;

procedure RoundRect (r: Rect; a: integer; LineType, Layer: integer);
begin
  Line (r.Left  + a, r.Bottom,     r.Right - a, r.Bottom,  LineType, Layer);
  Line (r.Left  + a, r.Top,        r.Right - a, r.Top,     LineType, Layer);
  Line (r.Left,      r.Bottom + a, r.Left,      r.Top - a, LineType, Layer);
  Line (r.Right,     r.Bottom + a, r.Right,     r.Top - a, LineType, Layer);
  Arc (0, r.Right - a, r.Top    - a, a, LineType, Layer);
  Arc (1, r.Left  + a, r.Top    - a);
  Arc (2, r.Left  + a, r.Bottom + a);
  Arc (3, r.Right - a, r.Bottom + a);
end;

procedure MitreRect (r: Rect; Corner: integer; LineType, Layer: integer);
begin
  Line (r.Left, r.Top, r.Right, r.Top, LineType, Layer);
  Line (r.Right, r.Bottom);
  Line (r.Left + Corner, r.Bottom);     {skosí levý dolní roh} 
  Line (r.Left, r.Bottom + Corner);
  Line (r.Left, r.Top);
end;

{ ---------------------------------------------------------------------------- }

var
  OutLineLayer, InnerLayer, LegendLayer: integer;
  OuterLine, InnerLine, LegendLine: integer;    {logické typy čar}

procedure CentralName (Center: Point; LineType, Layer: integer);
begin
  ComponentName    (Center.x, Center.y, 10, 0, LineType, Layer);
{ další dva nápisy vytvoří verze 4.40 automaticky, proto jsou vykomentovány }
{ ComponentValue   (Center.x, Center.y,  0, 0, LineType, Layer);  {nebo posunout kousek dolů?}
{ ComponentPackage (Center.x, Center.y,  0, 0, LineType, Layer);  {dtto}
end;

{ vytváření pouzder }

function um2gu (Micrometers: integer) : integer;        {převádí tisíciny mm na vnitřní jednotky}
begin
  Result := Micrometers div 25;
end;

procedure GenericTSSOP (Variation: string; N: integer; E, E1, D, Pitch: integer; PadType: integer;
                        PadOffset, OutlineMargin: integer);
var
  Name:  string;
  Frame: Rect;
  x, y:  integer;
  i:     integer;
begin
{ Name := 'TSSOP' + N + '-' + Pitch + '-' + E1; }
  Name := 'TSSOP-' + Variation;
  Component (Name, 'VALUE', Name) begin
    Frame := GetRect0 (um2gu (D) div 2, um2gu (E) div 2);
    CentralName (RectCenter (Frame), LegendLine, LegendLayer);
    MitreRect (StretchRect (Frame, 0, um2gu (OutlineMargin)), um2gu (500), OuterLine, OutlineLayer);
    x := -(N div 2 - 1) * Pitch div 2;  {souřadnice pinu 1 v tisícinách mm}
    y := um2gu (E + PadOffset) div 2;   {souřadnice horní řady ve vnitřních jednotkách}
    for i := 1 to N div 2 do
      DrawPin (i, um2gu (x + (i - 1) * Pitch), -y, PadType, 90);
    for i := N div 2 + 1 to N do
      DrawPin (i, um2gu (x + (N - i) * Pitch),  y, PadType, 90);
    DrawRect (GetRect0 (um2gu (D) div 2, um2gu (E1) div 2), InnerLine, InnerLayer);
    DrawCircle (GetPoint (um2gu (x), -y + 70), 20, InnerLine, InnerLayer);
  end;
end;

{ ---------------------------------------------------------------------------- }

var
  Pad065, Pad050, Pad040: integer;      {logické typy pájecích bodů pro jednotlivé rozteče vývodů}

begin
  OutlineLayer := 4 + 15 + 4;   {čísla vrstev zvýšena pro verzi 4.40}
  InnerLayer   := 4 + 14 + 4;
  LegendLayer  := 4 + 13 + 4;
  OuterLine  := 0;              {standardně odpovídá šířce 0,1  / 0,102 mm}
  InnerLine  := 1;              {standardně odpovídá šířce 0,15 / 0,152 mm}
  LegendLine := 2;              {standardně odpovídá šířce 0,2  / 0,203 mm}

  Pad065 := 85;
  Pad050 := 81;
  Pad040 := 33;         {hodnota užita jen pro odlišení od předchozích dvou;
                         v programu Layout nutno předefinovat včetně rozměrů}

{ ---------------------------------------------------------------------------- ]

  Následující tabulka vygeneruje řadu TSSOP pouzder dle normy JEDEC MO-153F,
  z které jsou přímo převzaty údaje v prvních šesti sloupcích (tj. prvních
  6 parametrů volané procedury).  Stejně tak je odtud převzato i jejich značení
  písmeny N až e v komentáři.

  Sedmý parametr je logický typ pájecího bodu.  Zde uvedené typy jsou pouze
  provizorní, vycházející z předdefinované tabulky rozměrů pájecích bodů
  v programu Layout.  Uživatel musí do proměnných Pad065, Pad050, Pad040 zapsat
  čísla typů odpovídající jeho vlastní tabulce rozměrů, popřípadě do ní nějaké
  pájecí body dodefinovat.

  Předposlední osmý parametr určuje posunutí středu pájecího bodu oproti poloze
  konce vývodu dle normy (záporná hodnota značí posunutí směrem k ose pouzdra).
  Hodnotu si může uživatel upravit podle zvoleného typu pájecího bodu a svých
  technologických požadavků.  Konečně devátý parametr udává posunutí vnějšího
  obrysu pouzdra vůči koncům vývodů.

  Všechny míry jsou uvedeny v tisícinách milimetru.

[ ---------------------------------------------------------------------------- }

  {             Variation N      E     E1      D     e   PadType          }     
  GenericTSSOP ('AA',     8,  6400,  4400,  3000,  650,  Pad065, -150, 500);
  GenericTSSOP ('AB-1',  14,  6400,  4400,  5000,  650,  Pad065, -150, 500);
  GenericTSSOP ('AB',    16,  6400,  4400,  5000,  650,  Pad065, -150, 500);
  GenericTSSOP ('AC',    20,  6400,  4400,  6500,  650,  Pad065, -150, 500);
  GenericTSSOP ('AD',    24,  6400,  4400,  7800,  650,  Pad065, -150, 500);
  GenericTSSOP ('AE',    28,  6400,  4400,  9700,  650,  Pad065, -150, 500);

  GenericTSSOP ('BA',    20,  6400,  4400,  5000,  500,  Pad050, -150, 500);
  GenericTSSOP ('BB',    24,  6400,  4400,  6500,  500,  Pad050, -150, 500);
  GenericTSSOP ('BC',    28,  6400,  4400,  7800,  500,  Pad050, -150, 500);
  GenericTSSOP ('BC-1',  30,  6400,  4400,  7800,  500,  Pad050, -150, 500);
  GenericTSSOP ('BD',    36,  6400,  4400,  9700,  500,  Pad050, -150, 500);
  GenericTSSOP ('BD-1',  38,  6400,  4400,  9700,  500,  Pad050, -150, 500);
  GenericTSSOP ('BE',    44,  6400,  4400, 11000,  500,  Pad050, -150, 500);
  GenericTSSOP ('BF',    50,  6400,  4400, 12500,  500,  Pad050, -150, 500);

  GenericTSSOP ('CA',    24,  6400,  4400,  5000,  400,  Pad040, -150, 500);
  GenericTSSOP ('CB',    32,  6400,  4400,  6500,  400,  Pad040, -150, 500);
  GenericTSSOP ('CC',    36,  6400,  4400,  7800,  400,  Pad040, -150, 500);
  GenericTSSOP ('CD',    48,  6400,  4400,  9700,  400,  Pad040, -150, 500);

  GenericTSSOP ('DA',    24,  8100,  6100,  7800,  650,  Pad065, -150, 500);
  GenericTSSOP ('DB',    28,  8100,  6100,  9700,  650,  Pad065, -150, 500);
  GenericTSSOP ('DB-1',  30,  8100,  6100,  9700,  650,  Pad065, -150, 500);
  GenericTSSOP ('DC',    32,  8100,  6100, 11000,  650,  Pad065, -150, 500);
  GenericTSSOP ('DD',    36,  8100,  6100, 12500,  650,  Pad065, -150, 500);
  GenericTSSOP ('DD-1',  38,  8100,  6100, 12500,  650,  Pad065, -150, 500);
  GenericTSSOP ('DE',    40,  8100,  6100, 14000,  650,  Pad065, -150, 500);

  GenericTSSOP ('EA',    28,  8100,  6100,  7800,  500,  Pad050, -150, 500);
  GenericTSSOP ('EB',    36,  8100,  6100,  9700,  500,  Pad050, -150, 500);
  GenericTSSOP ('EC',    40,  8100,  6100, 11000,  500,  Pad050, -150, 500);
  GenericTSSOP ('EC-1',  44,  8100,  6100, 11000,  500,  Pad050, -150, 500);
  GenericTSSOP ('ED',    48,  8100,  6100, 12500,  500,  Pad050, -150, 500);
  GenericTSSOP ('EE',    56,  8100,  6100, 14000,  500,  Pad050, -150, 500);
  GenericTSSOP ('EF',    64,  8100,  6100, 17000,  500,  Pad050, -150, 500);

  GenericTSSOP ('FA',    36,  8100,  6100,  7800,  400,  Pad040, -150, 500);
  GenericTSSOP ('FB',    48,  8100,  6100,  9700,  400,  Pad040, -150, 500);
  GenericTSSOP ('FC',    52,  8100,  6100, 11000,  400,  Pad040, -150, 500);
  GenericTSSOP ('FD',    56,  8100,  6100, 12500,  400,  Pad040, -150, 500);
  GenericTSSOP ('FE',    64,  8100,  6100, 14000,  400,  Pad040, -150, 500);
  GenericTSSOP ('FF',    80,  8100,  6100, 17000,  400,  Pad040, -150, 500);

  GenericTSSOP ('GA',    28, 10000,  8000,  9700,  650,  Pad065, -150, 500);
  GenericTSSOP ('GB',    32, 10000,  8000, 11000,  650,  Pad065, -150, 500);
  GenericTSSOP ('GC',    36, 10000,  8000, 12500,  650,  Pad065, -150, 500);
  GenericTSSOP ('GD',    40, 10000,  8000, 14700,  650,  Pad065, -150, 500);

  GenericTSSOP ('HA',    36, 10000,  8000,  9700,  500,  Pad050, -150, 500);
  GenericTSSOP ('HB',    40, 10000,  8000, 11000,  500,  Pad050, -150, 500);
  GenericTSSOP ('HC',    48, 10000,  8000, 12500,  500,  Pad050, -150, 500);
  GenericTSSOP ('HD',    56, 10000,  8000, 14000,  500,  Pad050, -150, 500);

  GenericTSSOP ('JA',    48, 10000,  8000,  9700,  400,  Pad040, -150, 500);
  GenericTSSOP ('JB',    52, 10000,  8000, 11000,  400,  Pad040, -150, 500);
  GenericTSSOP ('JC',    56, 10000,  8000, 12500,  400,  Pad040, -150, 500);
  GenericTSSOP ('JC-1',  60, 10000,  8000, 12500,  400,  Pad040, -150, 500);
  GenericTSSOP ('JD',    64, 10000,  8000, 14000,  400,  Pad040, -150, 500);
  GenericTSSOP ('JD-1',  68, 10000,  8000, 14000,  400,  Pad040, -150, 500);

  Writeln ('Vytvorena pouzdra TSSOP');
end.

