a tEDAx output module for gnetlist / lepton-netlist to use with pcb-rnd
[hw/altusmetrum] / scheme / gnet-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 " port)
60       (display "projectname" port)
61       (newline port)
62       (newline port)))
63
64 ;;
65 ;; trailer
66 ;;
67 (define tEDAx:trailer
68    (lambda (port)
69       (display "end netlist" port) 
70       (newline port)))
71
72 ;;
73 ;; component related lines 
74 ;;
75 (define tEDAx:components
76    (lambda (port ls)
77       (if (not (null? ls))
78          (let ((package (car ls)))
79             (begin
80                (display "\tfootprint " port)
81                (display package port)
82                (display " " port)
83                (display (tEDAx:get-pattern package) port)
84                (newline port)
85
86                (display "\tdevice " port)
87                (display package port)
88                (display " " port)
89                (display (tEDAx:get-device package) port)
90                (newline port)
91
92                (display "\tvalue " port)
93                (display package port)
94                (display " " port)
95                (display (tEDAx:get-value package) port)
96                (newline port)
97
98                (newline port)
99                (tEDAx:components port (cdr ls)))))))
100
101 (define (tEDAx:pinfmt pin)
102   (format #f "~a ~a" (car pin) (car (cdr pin)))
103   )
104
105 (define (tEDAx:each-pin net pins port)
106   (if (not (null? pins))
107       (let ((pin (car pins)))
108         (format port "\tconn ~a ~a~%" net (tEDAx:pinfmt pin))
109         (tEDAx:each-pin net (cdr pins) port))))
110
111 ;;
112 ;; network related lines 
113 ;;
114 (define (tEDAx:each-net netnames port)
115   (if (not (null? netnames))
116       (let ((netname (car netnames)))
117         (tEDAx:each-pin netname (gnetlist:get-all-connections netname) port)
118         (tEDAx:each-net (cdr netnames) port))))
119
120 ;;; 
121 ;;; output a tEDAx formatted netlist
122 ;;;
123 (define tEDAx
124    (lambda (output-filename)
125       (let ((port (open-output-file output-filename)))
126          (begin
127             (tEDAx:header port)
128             (tEDAx:components port packages)
129             (tEDAx:each-net (gnetlist:get-all-unique-nets "dummy") port)
130             (tEDAx:trailer port))
131          (close-output-port port))))
132
133 ;; --------------------------------------------------------------------------
134