e6af81a9304f2332de4b7964cd762ffe08acff51
[hw/altusmetrum] / 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\" \"%s\"]\n",
86                         name, num, 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\" \"%s\"]\n",
131                         name, num, 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                                      "square");
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         public void pad_mm_options(real center_x,
168                                    real center_y,
169                                    real width,
170                                    real height,
171                                    string name,
172                                    string num,
173                                    string options)
174         {
175                 pad_mm_clear_options(center_x,
176                                      center_y,
177                                      width,
178                                      height,
179                                      process_clearance,
180                                      name,
181                                      num,
182                                      options);
183         }
184
185         public void pad_mm_arbitrary(   real x1,
186                                         real y1,
187                                         real x2,
188                                         real y2,
189                                         real thickness,
190                                         string name,
191                                         string num,
192                                         string options)
193         {
194                 real clearance = process_clearance;
195
196                 real mask = thickness + clearance / 2;
197
198                 printf ("    Pad[");
199                 printf (" %6d %6d %6d %6d",
200                         mm2mils100(x1),
201                         mm2mils100(y1),
202                         mm2mils100(x2),
203                         mm2mils100(y2));
204                 printf (" %6d %6d %6d",
205                         mm2mils100(thickness),
206                         mm2mils100(clearance),
207                         mm2mils100(mask));
208                 printf (" \"%s\" \"%s\" \"%s\"]\n",
209                         name, num, options);
210         }
211
212         public void pin_mm_clear(real x, real y, real drill, real copper, real clearance,
213                         string name,
214                         string number)
215         {
216                 real thickness = drill + copper * 2;
217                 real mask = thickness + clearance / 2;
218                 printf("    Pin[");
219                 printf(" %6d %6d",
220                        mm2mils100(x),
221                        mm2mils100(y));
222                 printf(" %6d %6d %6d %6d",
223                        mm2mils100(thickness),
224                        mm2mils100(clearance),
225                        mm2mils100(mask),
226                        mm2mils100(drill));
227                 printf (" \"%s\" \"%s\"",
228                         name, number);
229                 printf (" \"\"]\n");
230                        
231         }
232
233         public void pin_mm_clear_options(real x, real y, real drill, real copper, real clearance,
234                                          string name,
235                                          string number,
236                                          string options)
237         {
238                 real thickness = drill + copper * 2;
239                 real mask = thickness + clearance / 2;
240                 printf("    Pin[");
241                 printf(" %6d %6d",
242                        mm2mils100(x),
243                        mm2mils100(y));
244                 printf(" %6d %6d %6d %6d",
245                        mm2mils100(thickness),
246                        mm2mils100(clearance),
247                        mm2mils100(mask),
248                        mm2mils100(drill));
249                 printf (" \"%s\" \"%s\"",
250                         name, number);
251                 printf (" \"%s\"]\n", options);
252                        
253         }
254
255         public void pin_mm_clear_mask_options(real x, real y,
256                                               real drill, real copper, real clearance, real mask,
257                                               string name, string number, string options)
258         {
259                 real thickness = drill + copper * 2;
260                 printf("    Pin[");
261                 printf(" %6d %6d",
262                        mm2mils100(x),
263                        mm2mils100(y));
264                 printf(" %6d %6d %6d %6d",
265                        mm2mils100(thickness),
266                        mm2mils100(clearance),
267                        mm2mils100(mask),
268                        mm2mils100(drill));
269                 printf (" \"%s\" \"%s\"",
270                         name, number);
271                 printf (" \"%s\"]\n", options);
272                        
273         }
274         public void pin_mm_clear_mask(real x, real y,
275                                       real drill, real copper, real clearance, real mask,
276                                       string name, string number)
277         {
278                 real thickness = copper;
279                 printf("    Pin[");
280                 printf(" %6d %6d",
281                        mm2mils100(x),
282                        mm2mils100(y));
283                 printf(" %6d %6d %6d %6d",
284                        mm2mils100(thickness),
285                        mm2mils100(clearance),
286                        mm2mils100(mask),
287                        mm2mils100(drill));
288                 printf (" \"%s\" \"%s\"",
289                         name, number);
290                 printf (" \"\"]\n");
291                        
292         }
293
294         public void pin_mm(real x, real y, real drill, real copper,
295                         string name,
296                         string number)
297         {
298                 pin_mm_clear(x, y, drill, copper, process_clearance,
299                              name, number);
300         }
301
302         public void pin_mm_options(real x, real y, real drill, real copper,
303                                    string name,
304                                    string number,
305                                    string options)
306         {
307                 pin_mm_clear_options(x, y, drill, copper, process_clearance,
308                                      name, number, options);
309         }
310
311         public void line (real x1, real y1, real x2, real y2)
312         {
313                 printf ("    ElementLine[");
314                 printf (" %6d %6d %6d %6d",
315                         mm2mils100(x1),
316                         mm2mils100(y1),
317                         mm2mils100(x2),
318                         mm2mils100(y2));
319                 printf (" %d]\n", line_thickness);
320         }
321
322         public void rect (real x, real y, real w, real h)
323         {
324                 line(x,y,x+w,y);
325                 line(x+w,y,x+w,y+h);
326                 line(x+w,y+h,x,y+h);
327                 line(x,y+h,x,y);
328         }
329
330         public void arc (real center_x, real center_y,
331                          real radius_x, real radius_y,
332                          real start_angle, real delta_angle)
333         {
334                 printf ("    ElementArc[ %6d %6d %6d %6d %3d %3d %d]\n",
335                         mm2mils100(center_x), mm2mils100(center_y),
336                         mm2mils100(radius_x), mm2mils100(radius_y),
337                         start_angle, delta_angle, line_thickness);
338         }
339 }