Accelerating eeschema symbol generation (code inside)

If you have ever used kicad, you’ve had a moment where there isn’t a ready-made symbol for your IC. It’s quick to make one with that  web tool but what what if the chip is over 100 pins?

I used to use a very dirty hack with bash and xdotool, but the amount of hackery here was a bit too big, so I decided to make a better solution. Lots of thanks fly out to the guys, who made xil2kc, a tool that creates eeschema symbols out of .pkg files that ISE can create. Unfortunately for me they picke python, my least favourite programming language. Anyway, the code was there, so I made a different util based on their library. I thought all the things over and came with a format that can be easily used.

So, how can we create a full-blown eeschema symbol in seconds? Instructions follow.

1. Open up your favourite pdf viewer with the datasheet (I use okular)
2. Copy the pin names in one or more sections of a text file
3. Define sorting rules and the number of subparts
4. run my utility, e.g. ./list2kc.py --pkg-file=./at91rm9200.pins --output-file=./at91rm9200.lib
5. Grab your eeschema library.

Let’s see how it actually works. For the test, Let’s pick something simple, like uln2003a
After 2 acts of copypasting, we get 2 groups of pins. One for pins 1 to 8 and second for pins 16 down to 9., since
I copypasted that from the top view.
The square brackets define the ranges, as you see below.

~subparts 1
:\dB:left:0
:\dC:right:0
:E:bot:0
:COM:top:0

[1:8]
1B
2B
3B
4B
5B
6B
7B
E
[16:9]
1C
2C
3C
4C
5C
6C
7C
COM

Next, is the header, that I’d like to point out.
The first line always defines the number of subparts.
Like ~subparts 1 tells us, that the symbol will only have 1 subpart.
Then, got the sorting rules.
Each string, before the section with pin names that starts with ‘:’ descibes a rule.
The utility iterates over this list and when a match is found, we have the location for the pin.
While mostly useless for something already in the eeschema library – it really saves some time,
when there’s something like over 200 pins to sort out.

The syntax of rules is as follows:
:regular_expression:where_to_put:what_subpart.
ex.  

:\dC:right:0

That just tells that we want to put pins, starting with a number,followed by ‘C’ to the right side of the subpart 0
(Yes, numbering here starts with 0, I’m more comfortable with that).
For more regexp VooDoo, see python docs for regular expressions
Well, that’s it. sources are at github here.
Beware, I’m not a fan of python, and rarely write anything in it. So the code might look strange.

Leave a Reply