README 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. fped - Footprint editor
  2. =======================
  3. fped is an editor that allows the interactive creation of footprints of
  4. electronic components. Footprint definitions are stored in a text format
  5. that resembles a programming language.
  6. The language is constrained such that anything that can be expressed in
  7. the textual definition also has a straightforward equivalent operation
  8. that can be performed through the GUI.
  9. This README describes only the footprint definition language. A
  10. description of the GUI can be found here:
  11. http://downloads.qi-hardware.com/people/werner/fped/gui.html
  12. This work is distributed under the terms of the GNU GENERAL PUBLIC
  13. LICENSE, Version 2:
  14. This program is free software; you can redistribute it and/or modify
  15. it under the terms of the GNU General Public License as published by
  16. the Free Software Foundation; either version 2 of the License, or
  17. (at your option) any later version.
  18. For your convenience, a copy of the complete license has been included
  19. in the file COPYING.GPLv2.
  20. Building
  21. --------
  22. Prerequisites:
  23. - bash
  24. - flex
  25. - bison
  26. - fig2dev (transfig)
  27. - ImageMagick
  28. - Netpbm
  29. - Gtk+ 2.x development package (libgtk2.0-dev or similar)
  30. - Liberation Fonts (ttf-liberation or similar)
  31. Check out the repository:
  32. git clone git://projects.qi-hardware.com/fped.git
  33. cd fped
  34. Get updates:
  35. git pull
  36. Compile:
  37. make
  38. Run an example:
  39. ./fped examples/qfn.fpd
  40. Motivation
  41. ----------
  42. KiCad already includes a footprint ("module") editor, so why do we need
  43. a new one ? The issue with footprint generation for KiCad is that the
  44. built-in module editor is basically a drawing program that only captures
  45. the result of the module author's interpretation of a footprint drawing,
  46. but does not include the steps that led to this construction.
  47. Furthermore, accurate measuring of dimensions in the drawing can only be
  48. done manually in the module editor, which makes review difficult and
  49. time-consuming.
  50. In fped, the construction process is made explicit and each step can be
  51. expressed in terms of the parameters that appear in the vendor's
  52. drawing. Dimensions can be explicitly measured and the results can be
  53. included in the graphical output generated by fped.
  54. Directly using parameters and construction steps from the reference
  55. drawing reduces the risk of mistakes. Visualizing the construction
  56. process and verificative measurements helps efficient and accurate
  57. review.
  58. Leveraging the work already done, and growing the intellectual commons
  59. of available footprints has motivated the addition of an export to gEDA
  60. pcb format option. Single or multiple footprints are exported in a
  61. gEDA PCB layout (.pcb) file. A select all command can be used, followed
  62. by a "disperse elements" command, to allow viewing of multiple elements
  63. in the gEDA layout editor. An element can then be selected, cut to
  64. buffer, and exported to a footprint (.fp) file with the usual menu
  65. commands.
  66. gEDA PCB format footprints are exported in centimil units. Pads with
  67. offset centre holes are not faithfully reproduced; the pad is exported
  68. with minimum dimensions and centred on the hole. Trapezoidal and
  69. roundrect pads are not supported in gEDA.
  70. Footprint definition file format
  71. --------------------------------
  72. Footprint definitions are stored in text files. The program "fped" reads
  73. and (soon) writes such files, visualizes their content, and provides a
  74. graphical editor for them.
  75. The syntax is unique and draws from elements of a variety of languages
  76. commonly found on unix systems. One specialty is that there are no
  77. reserved words - the language keywords appear only at the beginning of
  78. a line and can thus be recognized as such without restricting their use
  79. for identifiers. This reduces the risk of creating incompatibilities
  80. with existing designs when introduction future language features.
  81. fped uses the C preprocessor for comments, conditional compilation,
  82. and - to a limited extent - also macros. Long lines can be split by
  83. ending them with a backslash. If multiple items need to be placed in a
  84. single line, e.g., in a macro, they can be separated with semicolons.
  85. The file has the following structure:
  86. frame definitions
  87. ...
  88. package name
  89. setup
  90. objects
  91. ...
  92. Geometry model
  93. --------------
  94. The geometry model consists of frames, vectors, and objects. The shape of
  95. objects is defined by a number of points. These points are produced by
  96. concatenating vectors.
  97. E.g., to draw a line from (1mm, 1mm) to (2mm, 2mm), one would make a
  98. vector from the origin to (1mm, 1mm) and one either from the origin or
  99. from the previous vector to (2mm, 2mm), and then make a line connecting
  100. the two points.
  101. Setup
  102. - - -
  103. The setup section defines settings that affect the entire footprint.
  104. It is optional and can contain a "unit" directive and an "allow"
  105. directive.
  106. Units
  107. - - -
  108. fped can calculate in mm and mil. Units are specified by following a
  109. number with "mm", "um", or "mil", separated by zero or more spaces or
  110. tabs.
  111. Examples:
  112. 1mm
  113. 2 mil
  114. Units can be mixed in calculations, e.g.,
  115. set a = 1mm+20mil
  116. set b = 10*1mm
  117. All values used as dimensions must be either mm or mil.
  118. The default unit can be set with one of the following directives:
  119. unit mm
  120. unit mil
  121. unit auto
  122. If the "unit" directive is omitted, fped defaults to millimeters.
  123. When saving a footprint definition, the default unit is set to the
  124. unit set in the GUI.
  125. Allow
  126. - - -
  127. fped normally disallows overlapping pads. This restriction can be
  128. relaxed with the "allow" directive.
  129. allow touch
  130. Allows pads touching but not having more than their border in common.
  131. allow overlap
  132. Do not check for overlaps at all.
  133. If the "allow" directive is omitted, fped defaults to allowing
  134. neither overlap nor touch.
  135. There is also the following experimental directive that can be used
  136. alone or without one of the overlap-checking directives:
  137. allow holes
  138. Allow multiple holes per pad.
  139. Vectors
  140. - - - -
  141. Vectors can be anonymous or they can be named for future reference:
  142. vec <base> ( <x-expr>, <y-expr> )
  143. <identifier>: vec <base> ( <x-expr>, <y-expr> )
  144. The base can be one of the following items:
  145. - @ is the origin of the frame containing the vector
  146. - . is the end of the previous vector in this frame
  147. - <identifier> is the name of a previous vector in the same frame
  148. The following example would draw the line described in the previous
  149. section:
  150. a: vec @(1mm, 1mm)
  151. b: vec .(1mm, 1mm)
  152. line a b
  153. Silk screen objects
  154. - - - - - - - - - -
  155. The output of fped is a footprint definition that contains pads and silk
  156. screen drawings (we may add more layers in the future). These items are
  157. called "objects". Their geometry is defined through points obtained with
  158. vectors.
  159. A line connects two points:
  160. line <point-a> <point-b> [<width>]
  161. The points can be specified with @, ., and an identifier, just like
  162. a vector base. The option width specifies the thickness of the silk
  163. screen line. If omitted, a hard-coded default of 15 mil is used.
  164. A rectangle has sides parallel to the x and y axis and is defined
  165. by two diagonally opposite corners:
  166. rect <point-a> <point-b> [<width>]
  167. A circle is defined by its center and a point on the circle:
  168. circ <center> <point> [<width>]
  169. This example draws a unit circle:
  170. vec @(1mm, 0mm)
  171. circ @ .
  172. An arc is like a circle, but the part of the circle drawn is determined
  173. by two points. The first point determines the radius and the starting
  174. angle. The second point only determines the end angle but its distance
  175. from the center is ignored.
  176. arc <center> <radius> <end> [<width>]
  177. The arc is drawn in a counter-clockwise direction. The following example
  178. draws an arc of the unit circle in the x > 0, y > 0 quadrant:
  179. from: vec @(1mm, 0mm)
  180. to: vec @(0mm, 1mm)
  181. arc @ from to
  182. Pads
  183. - -
  184. Pads are similar to rectangles, but they also have a name.
  185. pad "<name>" <point-a> <point-b> [<type>]
  186. Variables can be expanded in a pad's name by prefixing their name with
  187. a dollar sign. The ${name} syntax is also available.
  188. Example:
  189. vec @(1mm, 1mm)
  190. pad "1" @ .
  191. Pads normally affect the surface copper layer, the solder mask layer,
  192. and the solder paste layer. This can be modified with the optional
  193. type argument:
  194. Type Layers
  195. --------- -------------------------------------
  196. (default) copper, solder mask, and solder paste
  197. bare copper and solder mask
  198. trace copper without solder mask opening
  199. paste solder paste
  200. mask solder mask
  201. Typical uses:
  202. - "bare": connectors printed directly on the PCB
  203. - "trace": connections or antennas
  204. - "paste": sparse solder paste, e.g., for QFN center pads
  205. - "mask": non-standard mask openings, e.g., for solder mask defined
  206. pads
  207. Rounded pads
  208. - - - - - -
  209. Rounded pads are like rectangular pads except that they end with a
  210. semi-circle at each of the smaller sides of the enclosing rectangle.
  211. If enclosed in a square, rounded pads form a circle.
  212. rpad "<name>" <point-a> <point-b> [<type>]
  213. Holes
  214. - - -
  215. Holes can be used for through-hole pins or for mechanical support.
  216. In the former case, the hole must be placed inside a pad. Only one
  217. hole per pad is allowed. Mechanical holes must be outside any pads.
  218. Through-hole pads are always present on both sides of the board, i.e.,
  219. when fped generates a KiCad module, the surface layers of a pad
  220. containing a hole are propagated to the opposite side of the board.
  221. Holes have the same shape as a rounded pad and their geometry is
  222. defined in the same way:
  223. hole <point-a> <point-b>
  224. Measurements
  225. - - - - - -
  226. *** This is obsolete - see the section on new-style mesurements at the end. ***
  227. Measurements show the distance between two points:
  228. meas <point-a> <point-b> <offset>
  229. The offset is the distance from the imaginary line connecting points A
  230. and B the measurement line is draw:
  231. - if the offset is 0mm, the line will connect A and B
  232. - if the offset is positive, the line would be on the left-hand side when
  233. traveling from A to B
  234. - if the offset is negative , the line would be on the right-hand side when
  235. traveling from A to B
  236. Example:
  237. a: vec @(-1mm, 1mm)
  238. b: vec @(1mm, 1mm)
  239. meas a b 0.2 mm
  240. Package name
  241. - - - - - -
  242. The package name is a non-empty string of printable ASCII characters,
  243. including spaces. If the "package" directive is omitted, fped defaults
  244. to using the name "_".
  245. package "<name>"
  246. Examples:
  247. package "48-SSOP"
  248. package "0603"
  249. Like in pad names, variables are expanded in package names. This allows
  250. the generation of multiple packages from a single definition.
  251. Frames
  252. - - -
  253. Frames are used to group things and to reuse them multiple times. Frames
  254. must be defined before they can be used:
  255. frame <name> {
  256. ... items ...
  257. }
  258. Once defined, a frame is placed at a given location with
  259. frame <name> <point>
  260. The frame definitions must precede all other items in a footprint
  261. description. Frames cannot be defined inside other frames, but frames
  262. can invoke each other recursively.
  263. For example, this puts two unity squares, one centered at (0 mm, 0 mm),
  264. the other at (2 mm, 0 mm):
  265. frame unit_square {
  266. a: vec @(-0.5mm, -0.5mm)
  267. b: vec .(1mm, 1mm)
  268. rect a b
  269. }
  270. frame unit_square @
  271. vec @(2mm, 0mm)
  272. frame unit_square .
  273. Names and variables
  274. -------------------
  275. fped uses several name spaces:
  276. - frame names occupy one global name space
  277. - vector names occupy name spaces delimited by the frame they're
  278. contained in. A vector name is only visible inside the frame in which
  279. it is defined.
  280. - variable names occupy name spaces delimited by the frame they're
  281. contained in. A variable lookup starts in the frame in which the
  282. corresponding expression appears and propagates to outer frames
  283. until the variable is found.
  284. - pads occupy one global name space (this is currently not enforced)
  285. Note that names cannot be redefined. E.g., this does not work:
  286. set a = 1
  287. set a = a+1
  288. The names spaces of frames, vectors, variables, and pads are separate
  289. from each other.
  290. Simple variables
  291. - - - - - - - -
  292. A variable with a single value is defined with the following
  293. assignment syntax:
  294. set <identifier> = <expression>
  295. Example:
  296. set a = b+2
  297. Loops
  298. - - -
  299. A loop is a variable with a range of values:
  300. loop <identifier> = <from>, <to>
  301. The variable assumes all the values i for <from> <= i <= <to>, in
  302. increments of one. E.g.,
  303. loop n = 1, 3
  304. and
  305. loop n = 1, 3.5
  306. both assign the values 1, 2, and 3 to the variable "n". The
  307. following loop would not execute at all:
  308. loop n = 1, 0
  309. This can be used to implement conditional execution. For example,
  310. the items in the following frame would be instantiated if the
  311. variable "enable" is set to 1 but not it is set to 0:
  312. frame ... {
  313. loop dummy = 1, enable
  314. ...
  315. }
  316. When a loop is executed, the objects contained in the body of the
  317. enclosing frame are generated for each value of the variable. If
  318. a frame contains multiple loops, all possible combinations of the
  319. values are generated.
  320. The following example draws three concentric circles around the
  321. origin, with radii 1, 2, and 3:
  322. loop x = 1, 3
  323. vec @(x*1mm, 0mm)
  324. circ @ .
  325. Tables
  326. - - -
  327. Tables combine values for multiple variables. Like loops, they are
  328. used to iteratively generate objects. A table begins with a row of
  329. variable names, followed by one or more rows with values. Rows are
  330. enclosed in curly braces and their elements are separated by commas.
  331. table
  332. { <identifier>, ... }
  333. { <expression>, ... }
  334. ...
  335. Like loops, tables are iterated to generate objects. The following
  336. example is equivalent to the one in the previous section:
  337. table
  338. { x }
  339. { 1mm }
  340. { 2mm }
  341. { 3mm }
  342. vec @(x, 0mm)
  343. circ @ .
  344. Note that we can set the unit of the values directly in this case.
  345. Iteration is performed over rows. All variables of the table are set
  346. to the value in the respective row at the same time. For example, in
  347. table
  348. { x, y }
  349. { 1, 2 }
  350. { 3, 4 }
  351. (x, y) assume the values (1, 2) and (3, 4).
  352. Tables can also be used to provide information that depends on
  353. other variables. The value of such a variable acts as a key, and a
  354. row is only selected if all the keys in that row match the
  355. respective variables. To mark a variable as being used as key, its
  356. name it prefixed with a question mark.
  357. Example:
  358. loop n = 1, 2, 3
  359. table
  360. { ?n, name }
  361. { 1, "one" }
  362. { 2, "two" }
  363. { 3, "three" }
  364. Expressions
  365. -----------
  366. Expressions can contain numeric constants (in non-exponential notation),
  367. variable names, the arithmetic operations +, -, *, /, unary -, and the
  368. functions sin(), cos(), sqrt(), and floor().
  369. Parentheses can be used to change precedence.
  370. The argument of sin and cos is a dimensionless number that specifies the
  371. angle in degrees. E.g., sin(90) yields 1.
  372. The argument of sqrt() can be dimensionless or have a dimension with an
  373. exponent that's a multiple of two. E.g., sqrt(2) and sqrt(2mm*3mm) are
  374. valid expressions, sqrt(2mm) isn't.
  375. The function floor() returns the next integer that is below or equal to
  376. the argument. If the argument has a dimension, that dimension is
  377. preserved. E.g., floor(-1.2) returns -2, floor(4.7mm) returns 4mm.
  378. GUI
  379. ---
  380. Part of the GUI is described in
  381. http://downloads.qi-hardware.com/people/werner/fped/gui.html
  382. Keyboard shortcuts
  383. - - - - - - - - -
  384. Space reset user coordinates
  385. +, = zoom in (like mouse wheel forward)
  386. - zoom out (like mouse wheel backward)
  387. . cursor position to screen center (like middle click)
  388. * zoom and center to extents
  389. # zoom and center to currently active frame instance
  390. U undelete the previously deleted object
  391. / Switch between variables, code, and packages display.
  392. Canvas
  393. - - -
  394. To create a new object, click on the corresponding tool icon, move the
  395. mouse to the base point of the new object, then drag to the object's
  396. second point.
  397. Frame references are created as follows:
  398. - select the frame you want to add
  399. - click on the frame icon. A black dot should appear on the icon.
  400. - select the frame on which you want to add the new reference.
  401. The black dot should change to a green dot. If the current frame
  402. is a child of the selected frame, the dot remains black.
  403. - click on the desired base location
  404. To change a point of an object, select the object, then drag the point
  405. to its new location. To edit the object's parameters, select it and
  406. make the changes in the input area at the bottom.
  407. To delete an object, select the delete tool and click on the object.
  408. Deleted objects can be undeleted by pressing "u". If any other changes
  409. have been made since deletion, fped may misbehave. If deleting a vector,
  410. all items that reference it are deleted as well.
  411. Experimental: new-style measurements
  412. ------------------------------------
  413. New-style measurements can measure the distance between various pairs
  414. of points, not only between points in the same instance and the same
  415. frame. They operate on the set of points produced during instantiation.
  416. New-style measurements are placed in the root frame after all other
  417. items.
  418. Known issues:
  419. - they currently can't be edited through the GUI
  420. - tie-breaking heuristics don't always do what one expects
  421. Syntax:
  422. <type> [<label>] <from> <op> <to> [<offset>]
  423. Types:
  424. - meas: measure diagonally
  425. - measx: measure along the X axis
  426. - measy: measure along the y axis
  427. Note that the type also affects the selection of the points. E.g.,
  428. measx will select maximum x values.
  429. Operators:
  430. - A -> B: smallest value of A and smallest B greater than A
  431. - A <- B: like A -> B, but normal (for offset and text) is inverted
  432. - A >> B: smallest value of A and greatest value of B
  433. - A << B: like A -> B, but normal (for offset and text) is inverted
  434. Operands are qualified vector names. Vectors in the root frame are
  435. referenced by their name. Vectors in other frames are prefixed with
  436. the name of the frame followed by a dot.
  437. Example:
  438. measx pad.sw -> pad.se 1mm
  439. The optional label is printed directly before the distance. Example:
  440. a: vec @(0mm, 0mm)
  441. b: vec @(1mm, 0mm)
  442. measx "width = " a >> b 0mm
  443. would print "width = 1mm"
  444. Additional qualifiers
  445. - - - - - - - - - - -
  446. When using frames as reusable building blocks, similar to functions or
  447. macros in many programming languages, one may need finer control over
  448. the points that are selected for measurements.
  449. For example, let us consider a frame "square" that draws a square
  450. centered at the frame's origin and with a side length given by the
  451. variable "size". This variable be set in the frame referencing
  452. "square".
  453. frame square {
  454. a: vec @(-size/2, -size/2)
  455. b: vec @(size/2, size/2)
  456. rect a b
  457. }
  458. frame small {
  459. set size = 2mm
  460. frame square @
  461. }
  462. frame big {
  463. set size = 5mm
  464. frame square @
  465. }
  466. frame small @
  467. vec @(5mm, 0mm)
  468. frame big .
  469. If we want to measure the size of each square, we could use
  470. measx square.a -> square.b
  471. Unfortunately, this only measures the small square. To reach the
  472. big frame, we need to tell fped to use only those points in "square"
  473. that have been placed when "square" was invoked from the big frame.
  474. This is accomplished by prefixing the points in question with the
  475. name(s) of the frames that need to be visited. The frame names are
  476. separated by slashes (/).
  477. measx big/square.a -> square.b
  478. For clarity, it's better to qualify both points, e.g.,
  479. measx big/square.a -> big/square.b
  480. If multiple frame names are given, they must be in the order in
  481. which they are invoked.
  482. Experimental: debugging directives
  483. ----------------------------------
  484. For debugging and regression tests, fped supports the following commands,
  485. most of which mimick the effect of GUI operations:
  486. %del <qualified-identifier>
  487. %move <identifier> [<number>] <identifier>
  488. %frame <identifier> <qualified-base>
  489. %print <expression>
  490. %iprint <expression>
  491. %meas <identifier>
  492. %dump
  493. %exit
  494. %tsort { -<id> | +<id> | <id-before> <id-after> [<number>] ... }
  495. %del removes the specified item. This can be a vector, an object, or
  496. a frame. If the vector or object is in a different frame than the
  497. current, its name is qualified with the frame name, e.g., "foo.obj".
  498. For this purpose, also objects can be labeled. Object labels behave like
  499. vector labels and share the same name space. They are not normally
  500. accessible in the GUI. (You can see them in the code view.)
  501. %move take as its first argument the name of the vector or object to
  502. manipulate. %move sets an anchor point to the vector named as its last
  503. argument. The anchor point is identified by index as follows:
  504. anchor index vec/frame line/rect/pad arc measurement
  505. -------------- --------- ------------- ------------ -----------
  506. 0 (or omitted) base first point center low point
  507. 1 - second point end of arc high point
  508. 2 - - start of arc -
  509. %frame creates a frame reference. Unlike "frame", the destination frame
  510. can be different from the current frame. E.g., "%frame foo bar.a" would
  511. add a reference to frame "foo" in frame "bar", rooted at vector "a". The
  512. parent frame's origin can be references as "@".
  513. %dump writes the footprint definition in the fped language to standard
  514. output. %exit immediately exits fped, without invoking the GUI.
  515. %print and %iprint evaluate the expression and print the result to
  516. standard output. The difference between them is that %print runs only
  517. once and without explicit instantiation, while %iprint is treated as
  518. a regular object and is executed as many times as instantiation
  519. demands.
  520. For example, after loop x = 1, 3 we would obtain just 1 with %print
  521. while %iprint would display, 1, 2, and 3.
  522. %meas performs an instantiation and prints the value of the labeled
  523. measurement.
  524. %tsort is used to test-drive the topological sort algorithm. The items
  525. in the curly braces are declarations of nodes with (-<id>) or without
  526. (+<id>) decay or edges in the partial order. The optional number is
  527. the edge's priority. See tsort.c for details, test/tsort for examples.