fa03e604ce8823d4a3ede599fc081910c236ca4a
[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 void element_start(string name) {
26                 printf ("# author: Keith Packard\n");
27                 printf ("# email: keithp@keithp.com\n");
28                 printf ("# dist-license: GPL 2\n");
29                 printf ("# use-license: unlimited\n");
30                 printf ("Element [\"\" \"%s\" \"\" \"\" 0 0 0 0 0 100 \"\"]\n",
31                         name);
32                 printf ("(\n");
33                 
34         }
35
36         public void element_end() {
37                 printf (")\n");
38         }
39         
40         public void pad_mm_clear(real center_x,
41                                  real center_y,
42                                  real width,
43                                  real height,
44                                  real clearance,
45                                  string name,
46                                  string num)
47         {
48                 real    x1 = 0;
49                 real    y1 = 0;
50                 real    x2 = 0;
51                 real    y2 = 0;
52                 real    thickness = 0;
53
54                 if (width > height) {
55                         thickness = height;
56                         y1 = center_y;
57                         x1 = center_x - (width - height) / 2;
58                         y2 = center_y;
59                         x2 = center_x + (width - height) / 2;
60                 } else {
61                         thickness = width;
62                         x1 = center_x;
63                         y1 = center_y - (height - width) / 2;
64                         x2 = center_x;
65                         y2 = center_y + (height - width) / 2;
66                 }
67
68                 real mask = thickness + clearance / 2;
69
70                 printf ("    Pad[");
71                 printf (" %6d %6d %6d %6d",
72                         mm2mils100(x1),
73                         mm2mils100(y1),
74                         mm2mils100(x2),
75                         mm2mils100(y2));
76                 printf (" %6d %6d %6d",
77                         mm2mils100(thickness),
78                         mm2mils100(clearance),
79                         mm2mils100(mask));
80                 printf (" \"%s\" \"%s\" \"square\"]\n",
81                         name, num);
82         }
83
84         public void pad_mm(real center_x,
85                            real center_y,
86                            real width,
87                            real height,
88                            string name,
89                            string num)
90         {
91                 pad_mm_clear(center_x,
92                              center_y,
93                              width,
94                              height,
95                              process_clearance,
96                              name,
97                              num);
98         }
99
100         public void pin_mm_clear(real x, real y, real drill, real copper, real clearance,
101                         string name,
102                         string number)
103         {
104                 real thickness = drill + copper * 2;
105                 real mask = thickness + clearance / 2;
106                 printf("    Pin[");
107                 printf(" %6d %6d",
108                        mm2mils100(x),
109                        mm2mils100(y));
110                 printf(" %6d %6d %6d %6d",
111                        mm2mils100(thickness),
112                        mm2mils100(clearance),
113                        mm2mils100(mask),
114                        mm2mils100(drill));
115                 printf (" \"%s\" \"%s\"",
116                         name, number);
117                 printf (" \"\"]\n");
118                        
119         }
120
121         public void pin_mm(real x, real y, real drill, real copper,
122                         string name,
123                         string number)
124         {
125                 pin_mm_clear(x, y, drill, copper, process_clearance,
126                              name, number);
127         }
128
129         public void line (real x1, real y1, real x2, real y2)
130         {
131                 printf ("    ElementLine[");
132                 printf (" %6d %6d %6d %6d",
133                         mm2mils100(x1),
134                         mm2mils100(y1),
135                         mm2mils100(x2),
136                         mm2mils100(y2));
137                 printf (" 1000]\n");
138         }
139
140         public void rect (real x, real y, real w, real h)
141         {
142                 line(x,y,x+w,y);
143                 line(x+w,y,x+w,y+h);
144                 line(x+w,y+h,x,y+h);
145                 line(x,y+h,x,y);
146         }
147 }