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