summaryrefslogtreecommitdiff
path: root/eagle-library-tool.mdwn
blob: e7db8e45efea9e790367ff452a303c4a217a6180 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
The problem
-----------

EAGLE is a decent CAD tool but it's library management is awful. Terrible. Almost *inconceivably* bad. You can't easily search for devices. You can't figure out what the devices are. The *dozens* of libraries that come with EAGLE are either hopelessly out of date or they're just pathetically done, with both overt and sometimes horrifically subtle errors. It's just a mess.

It's even *worse* when you try and collaborate with someone else, because libraries are just binary blobs. So as soon as you make one trivial change, your library is now incompatible with someone else's version. Because of this, we literally have more than 20 libraries, that are all subtly different, but probably have copies of copies of copies of footprints, all different.

Also, you find that for every library you make, you tend to copy symbols and packages around, so that you tend to have a dozen subtly different footprints, or even symbols, for the same thing.

We can fix a bit of this, we think.

EAGLE Libraries
---------------

There are three things inside EAGLE libraries (binary blobs with file extension ".lbr"):

- **Symbols** are the schematic representations of devices. They have *pins*, which are the "nodes" of the device in a netlist.
- **Packages** are the footprints on the PCB of the devices. They have *pads*, which are  electrically separate (usually) connections.
- **Devices** are this mappings of one or more symbols to one or more packages. As far as we know, the number of pins always has to equal the number of pads.

Luckily, we can export EAGLE libraries to "script" files (.scr), which are just text files filled with EAGLE commands to recreate the symbols/packages/devices. (the command line command is `eagle -C"export script file.scr;quit" file.lbr`). Inside the script file is:

**Header:** This sets up the grid, layer names, and other misc. stuff. So far, it tends to be the same for everything, although I'm just sure there are differences :)

**Symbols:** Symbols always start with the line `Edit 'symbol-name.sym';` and then have EAGLE commands, one per line, after that, until the symbol description is terminated by a blank line.

**Packages:** Packages always start with the line `Edit 'package-name.pac';` and then have EAGLE commands, one per line, after that, until the package description is terminated by a blank line.

**Devices:** Devices always start with the line `Edit 'devices-name.dev';` and then have EAGLE commands, one per line, after that, until the device description is terminated by a blank line. Inside the device description are `Add` commands which add Symbols to the device, and `Package` commands which add packages, Note that devices *must* be below Symbols and Packages in the SCR file since they have to refer to "already existing" Symbols and Packages.


Our proposed solution
---------------------

### Exploding Libraries

Create a script (python? bash?) that does somethng like the following.

1. Given a library file (.lbr), run EAGLE and create a temporary script file (.scr).
2. Break up the temporary script file and save symbols, packages, and devices (let's call each of these a 'unit') as separate files in their own directories ('sym', 'pac' and 'dev').
3. Every time the script tries to save a unit in the appropriate directory, it may find that this name already exists. If so, it should do a diff and discard the current unit if an exact copy of it already exits. If there's a file with the same name but different contents, then it should try to save as `name-n` where n is an incrementing number. If *that* file exits, it should try and diff on that, and if they're the same, discard the current unit. It should continue with this file checking until either it finds an exact copy, or a unique filename.

### User Cleanup and Commit

At this point, we've exploded one or more libraries into these three directories. We can then go through and prune the various packages (and in some cases, symbols) until we have the "best" units picked out - the most correct packages, the best looking symbols, etc. And then, of course, we can check them in! With merging! Yay, tools like git.

### Imploding Scripts

Once we've pruned and modified and are happy with the scripts, then we want to implode them all back into a single script file and turn that script file back into a library.

1. Cat all of the symbols, package and devices into a single temporary script file.
2. Possibly wait on devices, and only add them if their existing package and devices are already in the temporary script file. 
3. Run EAGLE and turn the temporary script file into a EAGLE library file.

A handy additional command would be to give the name of a device, and have the command grab the device file, parse it for symbol and package names, and then grab those files, create a temporary script, and turn that into an EAGLE file.

### Example files

Attached is a small EAGLE library ([[ZXMP6A17.lbr]]) and script file ([[ZXMP6A17.scr]]) to play around with.