Initial cut at pogo-pin mounting board for micropeak
[hw/mppogo] / 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 clearance_mm = 0.6;
22         public real clearance_mil = 25;
23
24         public int mm2mils100(real mm) = floor (mm / 25.4 * 1000 * 100 + 0.5);
25
26         public int mils2mils100(real mils) = floor (mils * 100 + 0.5);
27
28         public void element_start(string name) {
29                 printf ("# author: Keith Packard\n");
30                 printf ("# email: keithp@keithp.com\n");
31                 printf ("# dist-license: GPL 2\n");
32                 printf ("# use-license: unlimited\n");
33                 printf ("Element [\"\" \"%s\" \"\" \"\" 0 0 0 0 0 100 \"\"]\n",
34                         name);
35                 printf ("(\n");
36                 
37         }
38
39         public void element_end() {
40                 printf (")\n");
41         }
42         
43         public void pad_mm(real center_x,
44                            real center_y,
45                            real width,
46                            real height,
47                            string name,
48                            string num)
49         {
50                 real    x1 = 0;
51                 real    y1 = 0;
52                 real    x2 = 0;
53                 real    y2 = 0;
54                 real    thickness = 0;
55
56                 if (width > height) {
57                         thickness = height;
58                         y1 = center_y;
59                         x1 = center_x - (width - height) / 2;
60                         y2 = center_y;
61                         x2 = center_x + (width - height) / 2;
62                 } else {
63                         thickness = width;
64                         x1 = center_x;
65                         y1 = center_y - (height - width) / 2;
66                         x2 = center_x;
67                         y2 = center_y + (height - width) / 2;
68                 }
69
70                 real mask = thickness + clearance_mm / 2;
71
72                 printf ("    Pad[");
73                 printf (" %6d %6d %6d %6d",
74                         mm2mils100(x1),
75                         mm2mils100(y1),
76                         mm2mils100(x2),
77                         mm2mils100(y2));
78                 printf (" %6d %6d %6d",
79                         mm2mils100(thickness),
80                         mm2mils100(clearance_mm),
81                         mm2mils100(mask));
82                 printf (" \"%s\" \"%s\" \"square\"]\n",
83                         name, num);
84         }
85
86         public void pin_mm(real x, real y, real drill, real copper,
87                         string name,
88                         string number)
89         {
90                 real thickness = drill + copper * 2;
91                 real mask = thickness + clearance_mm / 2;
92                 printf("    Pin[");
93                 printf(" %6d %6d",
94                        mm2mils100(x),
95                        mm2mils100(y));
96                 printf(" %6d %6d %6d %6d",
97                        mm2mils100(thickness),
98                        mm2mils100(clearance_mm),
99                        mm2mils100(mask),
100                        mm2mils100(drill));
101                 printf (" \"%s\" \"%s\"",
102                         name, number);
103                 printf (" \"\"]\n");
104                        
105         }
106
107         public void pin_mil(real x, real y, real drill, real copper,
108                         string name,
109                         string number)
110         {
111                 real thickness = drill + copper * 2;
112                 real mask = thickness + clearance_mil / 2;
113                 printf("    Pin[");
114                 printf(" %6d %6d",
115                        mils2mils100(x),
116                        mils2mils100(y));
117                 printf(" %6d %6d %6d %6d",
118                        mils2mils100(thickness),
119                        mils2mils100(clearance_mil),
120                        mils2mils100(mask),
121                        mils2mils100(drill));
122                 printf (" \"%s\" \"%s\"",
123                         name, number);
124                 printf (" \"\"]\n");
125                        
126         }
127
128         public void line_mm (real x1, real y1, real x2, real y2)
129         {
130                 printf ("    ElementLine[");
131                 printf (" %6d %6d %6d %6d",
132                         mm2mils100(x1),
133                         mm2mils100(y1),
134                         mm2mils100(x2),
135                         mm2mils100(y2));
136                 printf (" 1000]\n");
137         }
138
139         public void line_mil (real x1, real y1, real x2, real y2)
140         {
141                 printf ("    ElementLine[");
142                 printf (" %6d %6d %6d %6d",
143                         mils2mils100(x1),
144                         mils2mils100(y1),
145                         mils2mils100(x2),
146                         mils2mils100(y2));
147                 printf (" 1000]\n");
148         }
149
150         public void rect_mm (real x, real y, real w, real h)
151         {
152                 line_mm(x,y,x+w,y);
153                 line_mm(x+w,y,x+w,y+h);
154                 line_mm(x+w,y+h,x,y+h);
155                 line_mm(x,y+h,x,y);
156         }
157
158         public void rect_mil (real x, real y, real w, real h)
159         {
160                 line_mil(x,y,x+w,y);
161                 line_mil(x+w,y,x+w,y+h);
162                 line_mil(x+w,y+h,x,y+h);
163                 line_mil(x,y+h,x,y);
164         }
165 }