Fix STM footprint to include TI-style pad with vias
[hw/telegps] / packages / footprint.5c
1 /*
2  * Copyright © 2012 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 namespace Footprint {
19
20         /* process clearance requirement */
21         public real process_clearance = 0.6;
22
23         public int mm2mils100(real mm) = floor (mm / 25.4 * 1000 * 100 + 0.5);
24
25         public real mils1002mm(real mils100) = mils100 * 25.4 / 100 / 1000;
26
27         public int line_thickness = 1000;
28
29         public void element_start(string name) {
30                 printf ("# author: Keith Packard\n");
31                 printf ("# email: keithp@keithp.com\n");
32                 printf ("# dist-license: GPL 2\n");
33                 printf ("# use-license: unlimited\n");
34                 printf ("Element [\"\" \"%s\" \"\" \"\" 0 0 0 0 0 100 \"\"]\n",
35                         name);
36                 printf ("(\n");
37                 
38         }
39
40         public void element_end() {
41                 printf (")\n");
42         }
43         
44         public void pad_mm_clear_mask_options(real center_x,
45                                               real center_y,
46                                               real width,
47                                               real height,
48                                               real clearance,
49                                               real mask,
50                                               string name,
51                                               string num,
52                                               string options)
53         {
54                 real    x1 = 0;
55                 real    y1 = 0;
56                 real    x2 = 0;
57                 real    y2 = 0;
58                 real    thickness = 0;
59
60                 if (width > height) {
61                         thickness = height;
62                         y1 = center_y;
63                         x1 = center_x - (width - height) / 2;
64                         y2 = center_y;
65                         x2 = center_x + (width - height) / 2;
66                 } else {
67                         thickness = width;
68                         x1 = center_x;
69                         y1 = center_y - (height - width) / 2;
70                         x2 = center_x;
71                         y2 = center_y + (height - width) / 2;
72                 }
73
74
75                 printf ("    Pad[");
76                 printf (" %6d %6d %6d %6d",
77                         mm2mils100(x1),
78                         mm2mils100(y1),
79                         mm2mils100(x2),
80                         mm2mils100(y2));
81                 printf (" %6d %6d %6d",
82                         mm2mils100(thickness),
83                         mm2mils100(clearance),
84                         mm2mils100(mask));
85                 printf (" \"%s\" \"%s\" \"square%s%s\"]\n",
86                         name, num, options == "" ? "" : ",", options);
87         }
88
89         public void pad_mm_clear_options(real center_x,
90                                          real center_y,
91                                          real width,
92                                          real height,
93                                          real clearance,
94                                          string name,
95                                          string num,
96                                          string options)
97         {
98                 real    x1 = 0;
99                 real    y1 = 0;
100                 real    x2 = 0;
101                 real    y2 = 0;
102                 real    thickness = 0;
103
104                 if (width > height) {
105                         thickness = height;
106                         y1 = center_y;
107                         x1 = center_x - (width - height) / 2;
108                         y2 = center_y;
109                         x2 = center_x + (width - height) / 2;
110                 } else {
111                         thickness = width;
112                         x1 = center_x;
113                         y1 = center_y - (height - width) / 2;
114                         x2 = center_x;
115                         y2 = center_y + (height - width) / 2;
116                 }
117
118                 real mask = thickness + clearance / 2;
119
120                 printf ("    Pad[");
121                 printf (" %6d %6d %6d %6d",
122                         mm2mils100(x1),
123                         mm2mils100(y1),
124                         mm2mils100(x2),
125                         mm2mils100(y2));
126                 printf (" %6d %6d %6d",
127                         mm2mils100(thickness),
128                         mm2mils100(clearance),
129                         mm2mils100(mask));
130                 printf (" \"%s\" \"%s\" \"square%s%s\"]\n",
131                         name, num, options == "" ? "" : ",", options);
132         }
133
134         public void pad_mm_clear(real center_x,
135                                  real center_y,
136                                  real width,
137                                  real height,
138                                  real clearance,
139                                  string name,
140                                  string num)
141         {
142                 pad_mm_clear_options(center_x,
143                                      center_y,
144                                      width,
145                                      height,
146                                      clearance,
147                                      name,
148                                      num,
149                                      "");
150         }
151
152         public void pad_mm(real center_x,
153                            real center_y,
154                            real width,
155                            real height,
156                            string name,
157                            string num)
158         {
159                 pad_mm_clear(center_x,
160                              center_y,
161                              width,
162                              height,
163                              process_clearance,
164                              name,
165                              num);
166         }
167
168         public void pin_mm_clear(real x, real y, real drill, real copper, real clearance,
169                         string name,
170                         string number)
171         {
172                 real thickness = drill + copper * 2;
173                 real mask = thickness + clearance / 2;
174                 printf("    Pin[");
175                 printf(" %6d %6d",
176                        mm2mils100(x),
177                        mm2mils100(y));
178                 printf(" %6d %6d %6d %6d",
179                        mm2mils100(thickness),
180                        mm2mils100(clearance),
181                        mm2mils100(mask),
182                        mm2mils100(drill));
183                 printf (" \"%s\" \"%s\"",
184                         name, number);
185                 printf (" \"\"]\n");
186                        
187         }
188
189         public void pin_mm_clear_mask(real x, real y,
190                                       real drill, real copper, real clearance, real mask,
191                                       string name, string number)
192         {
193                 real thickness = drill + copper * 2;
194                 printf("    Pin[");
195                 printf(" %6d %6d",
196                        mm2mils100(x),
197                        mm2mils100(y));
198                 printf(" %6d %6d %6d %6d",
199                        mm2mils100(thickness),
200                        mm2mils100(clearance),
201                        mm2mils100(mask),
202                        mm2mils100(drill));
203                 printf (" \"%s\" \"%s\"",
204                         name, number);
205                 printf (" \"\"]\n");
206                        
207         }
208
209         public void pin_mm(real x, real y, real drill, real copper,
210                         string name,
211                         string number)
212         {
213                 pin_mm_clear(x, y, drill, copper, process_clearance,
214                              name, number);
215         }
216
217         public void line (real x1, real y1, real x2, real y2)
218         {
219                 printf ("    ElementLine[");
220                 printf (" %6d %6d %6d %6d",
221                         mm2mils100(x1),
222                         mm2mils100(y1),
223                         mm2mils100(x2),
224                         mm2mils100(y2));
225                 printf (" %d]\n", line_thickness);
226         }
227
228         public void rect (real x, real y, real w, real h)
229         {
230                 line(x,y,x+w,y);
231                 line(x+w,y,x+w,y+h);
232                 line(x+w,y+h,x,y+h);
233                 line(x,y+h,x,y);
234         }
235 }