Xué video camera
Sign in or create your account | Project List | Help
Xué video camera Git Source Tree
Root/
| 1 | #!/usr/bin/python |
| 2 | # -*- coding: utf-8 -*- |
| 3 | """ |
| 4 | Copyright (C) 2010 Andres Calderon, andres.calderon@emqbit.com |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation; either version 2 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | |
| 20 | """ |
| 21 | |
| 22 | import re |
| 23 | import sys |
| 24 | import getopt |
| 25 | from kccomp import * |
| 26 | |
| 27 | def usage(appname): |
| 28 | print "usage : " + appname + " --pkg-file=inputfile.pkg --output-file=output.lib" |
| 29 | |
| 30 | def main(): |
| 31 | try: |
| 32 | opts, args = getopt.getopt(sys.argv[1:], 'p:o:', ['pkg-file=', 'output-file=']) |
| 33 | except getopt.GetoptError: |
| 34 | usage(sys.argv[0]) |
| 35 | sys.exit(2) |
| 36 | |
| 37 | inputfile=None |
| 38 | outputfile=None |
| 39 | for o, a in opts: |
| 40 | if o in ("-p", "--pkg-file"): |
| 41 | inputfile = a |
| 42 | elif o in ("-o", "--output-file"): |
| 43 | outputfile = a |
| 44 | |
| 45 | if inputfile==None: |
| 46 | usage(sys.argv[0]) |
| 47 | sys.exit(2) |
| 48 | |
| 49 | part = inputfile.split('.')[0] |
| 50 | if outputfile==None: |
| 51 | outputfile = part+'.lib' |
| 52 | |
| 53 | f = open(inputfile,'r') |
| 54 | |
| 55 | pl = re.compile('^(pin|pkgpin)') |
| 56 | pins = [] |
| 57 | |
| 58 | for line in f.read().split('\n'): |
| 59 | if pl.search(line): |
| 60 | tags = re.split('\s+',line) |
| 61 | # pin or function pin vref vcco |
| 62 | # pkgpin name name bank bank |
| 63 | pins.append((tags[0],tags[5], tags[2],tags[3],tags[4])) |
| 64 | |
| 65 | f.close() |
| 66 | |
| 67 | m = {} |
| 68 | for i in xrange(len(pins)): |
| 69 | if not m.has_key(pins[i][4]): |
| 70 | m[pins[i][4]] = [] |
| 71 | m[pins[i][4]].append(i) |
| 72 | |
| 73 | xl = KcLibrary (outputfile) |
| 74 | |
| 75 | comp = KcComponent(part); |
| 76 | |
| 77 | xl.add_part(comp) |
| 78 | |
| 79 | subpart=1 |
| 80 | for id_bank in m: |
| 81 | un = KcUnit(subpart) |
| 82 | comp.add_unit(un) |
| 83 | subpart=subpart+1 |
| 84 | |
| 85 | signals = [] |
| 86 | for signal in m[id_bank]: |
| 87 | if re.search("VCC",pins[signal][1]): |
| 88 | un.top_pins.append(KcPin(pins[signal][1],pins[signal][2])) |
| 89 | else: |
| 90 | if re.search("GND",pins[signal][1]): |
| 91 | un.bot_pins.append(KcPin(pins[signal][1],pins[signal][2])) |
| 92 | else: |
| 93 | signals.append(KcPin(pins[signal][1],pins[signal][2])) |
| 94 | |
| 95 | #signals=sorted(signals, key=lambda KcPin: KcPin.name) |
| 96 | |
| 97 | #for signal in signals: |
| 98 | #if(signal.name=="NC"): |
| 99 | #signal.pin_type = 'N' |
| 100 | |
| 101 | sp=len(signals)/2 |
| 102 | for signal in signals[0:sp]: |
| 103 | un.left_pins.append(signal) |
| 104 | |
| 105 | for signal in signals[sp:]: |
| 106 | un.right_pins.append(signal) |
| 107 | |
| 108 | xl.write() |
| 109 | |
| 110 | #end-main |
| 111 | |
| 112 | if __name__ == "__main__": |
| 113 | main() |
| 114 |
Branches:
master
