upate gnet-tEDAx.scm to work with lepton-eda, preserve geda-gaf version too
[hw/altusmetrum] / scheme / geda-gaf-tEDAx.scm
1 ;;; gEDA - GPL Electronic Design Automation
2 ;;; gnetlist plug-in for tEDAx
3 ;;; Copyright (C) 2018 Bdale Garbee
4 ;;;
5 ;;; This program is free software; you can redistribute it and/or modify
6 ;;; it under the terms of the GNU General Public License as published by
7 ;;; the Free Software Foundation; either version 2 of the License, or
8 ;;; (at your option) any later version.
9 ;;;
10 ;;; This program is distributed in the hope that it will be useful,
11 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ;;; GNU General Public License for more details.
14 ;;;
15 ;;; You should have received a copy of the GNU General Public License
16 ;;; along with this program; if not, write to the Free Software
17 ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 ;;; MA 02111-1301 USA.
19
20 ;; --------------------------------------------------------------------------
21
22 ;;
23 ;; returns the device attribute value
24 ;;
25 (define tEDAx:get-device
26    (lambda (package)
27       (gnetlist:get-package-attribute package "device")))
28
29 ;;
30 ;; returns the footprint attribute value (PATTERN if not defined)
31 ;;
32 (define tEDAx:get-pattern
33    (lambda (package)
34       (define pattern (gnetlist:get-package-attribute package "footprint"))
35       (if (string=? "unknown" pattern)
36          "PATTERN"
37          pattern)))
38 ; how do i return "PATTERN" if not defined? humm... need to read some
39 ; guile stuff... i did, and see the result :)
40
41 ;;
42 ;; returns the value attribute (empty if not defined)
43 ;;
44 (define tEDAx:get-value
45    (lambda (package)
46       (define value (gnetlist:get-package-attribute package "value"))
47       (if (string=? "unknown" value)
48          ""
49          value)))
50  
51 ;;
52 ;; header
53 ;;
54 (define tEDAx:header
55    (lambda (port)
56       (display "tEDAx v1" port) 
57       (newline port)
58
59       (display "begin netlist v1 netlist" port)
60       (newline port)
61       (newline port)))
62
63 ;;
64 ;; trailer
65 ;;
66 (define tEDAx:trailer
67    (lambda (port)
68       (display "end netlist" port) 
69       (newline port)))
70
71 ;;
72 ;; component related lines 
73 ;;
74 (define tEDAx:components
75    (lambda (port ls)
76       (if (not (null? ls))
77          (let ((package (car ls)))
78             (begin
79                (display "\tfootprint " port)
80                (display package port)
81                (display " " port)
82                (display (tEDAx:get-pattern package) port)
83                (newline port)
84
85                (display "\tdevice " port)
86                (display package port)
87                (display " " port)
88                (display (tEDAx:get-device package) port)
89                (newline port)
90
91                (display "\tvalue " port)
92                (display package port)
93                (display " " port)
94                (display (tEDAx:get-value package) port)
95                (newline port)
96
97                (newline port)
98                (tEDAx:components port (cdr ls)))))))
99
100 (define (tEDAx:pinfmt pin)
101   (format #f "~a ~a" (car pin) (car (cdr pin)))
102   )
103
104 (define (tEDAx:each-pin net pins port)
105   (if (not (null? pins))
106       (let ((pin (car pins)))
107         (format port "\tconn ~a ~a~%" net (tEDAx:pinfmt pin))
108         (tEDAx:each-pin net (cdr pins) port))))
109
110 ;;
111 ;; network related lines 
112 ;;
113 (define (tEDAx:each-net netnames port)
114   (if (not (null? netnames))
115       (let ((netname (car netnames)))
116         (tEDAx:each-pin netname (gnetlist:get-all-connections netname) port)
117         (tEDAx:each-net (cdr netnames) port))))
118
119 ;;; 
120 ;;; output a tEDAx formatted netlist
121 ;;;
122 (define tEDAx
123    (lambda (output-filename)
124       (let ((port (open-output-file output-filename)))
125          (begin
126             (tEDAx:header port)
127             (tEDAx:components port packages)
128             (tEDAx:each-net (gnetlist:get-all-unique-nets "dummy") port)
129             (tEDAx:trailer port))
130          (close-output-port port))))
131
132 ;; --------------------------------------------------------------------------
133